4 // Core drawing code for Aven.
6 // Copyright (C) 2000-2003,2005,2006 Mark R. Shinwell
7 // Copyright (C) 2001-2003,2004,2005,2006,2007,2010,2011,2012,2014,2015,2016,2017 Olly Betts
8 // Copyright (C) 2005 Martin Green
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.
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.
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
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #include "guicontrol.h"
41 #include "moviemaker.h"
43 #include <wx/confbase.h>
44 #include <wx/wfstream.h>
46 #include <wx/zipstrm.h>
50 const unsigned long DEFAULT_HGT_DIM
= 3601;
51 const unsigned long DEFAULT_HGT_SIZE
= sqrd(DEFAULT_HGT_DIM
) * 2;
53 // Values for m_SwitchingTo
61 // Any error value higher than this is clamped to this.
62 #define MAX_ERROR 12.0
64 // Any length greater than pow(10, LOG_LEN_MAX) will be clamped to this.
65 const Double LOG_LEN_MAX
= 1.5;
67 // How many bins per letter height to use when working out non-overlapping
69 const unsigned int QUANTISE_FACTOR
= 2;
73 static const int INDICATOR_BOX_SIZE
= 60;
74 static const int INDICATOR_GAP
= 2;
75 static const int INDICATOR_MARGIN
= 5;
76 static const int INDICATOR_OFFSET_X
= 15;
77 static const int INDICATOR_OFFSET_Y
= 15;
78 static const int INDICATOR_RADIUS
= INDICATOR_BOX_SIZE
/ 2 - INDICATOR_MARGIN
;
79 static const int KEY_OFFSET_X
= 10;
80 static const int KEY_OFFSET_Y
= 10;
81 static const int KEY_EXTRA_LEFT_MARGIN
= 2;
82 static const int KEY_BLOCK_WIDTH
= 20;
83 static const int KEY_BLOCK_HEIGHT
= 16;
84 static const int TICK_LENGTH
= 4;
85 static const int SCALE_BAR_OFFSET_X
= 15;
86 static const int SCALE_BAR_OFFSET_Y
= 12;
87 static const int SCALE_BAR_HEIGHT
= 12;
89 static const gla_colour TEXT_COLOUR
= col_GREEN
;
90 static const gla_colour HERE_COLOUR
= col_WHITE
;
91 static const gla_colour NAME_COLOUR
= col_GREEN
;
92 static const gla_colour SEL_COLOUR
= col_WHITE
;
94 // Number of entries across and down the hit-test grid:
95 #define HITTEST_SIZE 20
97 // How close the pointer needs to be to a station to be considered:
98 #define MEASURE_THRESHOLD 7
100 // vector for lighting angle
101 static const Vector3
light(.577, .577, .577);
103 BEGIN_EVENT_TABLE(GfxCore
, GLACanvas
)
104 EVT_PAINT(GfxCore::OnPaint
)
105 EVT_LEFT_DOWN(GfxCore::OnLButtonDown
)
106 EVT_LEFT_UP(GfxCore::OnLButtonUp
)
107 EVT_MIDDLE_DOWN(GfxCore::OnMButtonDown
)
108 EVT_MIDDLE_UP(GfxCore::OnMButtonUp
)
109 EVT_RIGHT_DOWN(GfxCore::OnRButtonDown
)
110 EVT_RIGHT_UP(GfxCore::OnRButtonUp
)
111 EVT_MOUSEWHEEL(GfxCore::OnMouseWheel
)
112 EVT_MOTION(GfxCore::OnMouseMove
)
113 EVT_LEAVE_WINDOW(GfxCore::OnLeaveWindow
)
114 EVT_SIZE(GfxCore::OnSize
)
115 EVT_IDLE(GfxCore::OnIdle
)
116 EVT_CHAR(GfxCore::OnKeyPress
)
119 GfxCore::GfxCore(MainFrm
* parent
, wxWindow
* parent_win
, GUIControl
* control
) :
120 GLACanvas(parent_win
, 100),
127 m_DoneFirstShow(false),
135 m_Splays(SHOW_FADED
),
136 m_Dupes(SHOW_DASHED
),
140 m_OverlappingNames(false),
144 m_ColourBy(COLOUR_BY_DEPTH
),
147 m_MouseOutsideCompass(false),
148 m_MouseOutsideElev(false),
152 m_ExportedPts(false),
154 m_BoundingBox(false),
159 m_HitTestDebug(false),
160 m_RenderStats(false),
162 m_HitTestGridValid(false),
165 presentation_mode(0),
169 current_cursor(GfxCore::CURSOR_DEFAULT
),
170 sqrd_measure_threshold(sqrd(MEASURE_THRESHOLD
)),
175 AddQuad
= &GfxCore::AddQuadrilateralDepth
;
176 AddPoly
= &GfxCore::AddPolylineDepth
;
177 wxConfigBase::Get()->Read(wxT("metric"), &m_Metric
, true);
178 wxConfigBase::Get()->Read(wxT("degrees"), &m_Degrees
, true);
179 wxConfigBase::Get()->Read(wxT("percent"), &m_Percent
, false);
181 for (int pen
= 0; pen
< NUM_COLOUR_BANDS
+ 1; ++pen
) {
182 m_Pens
[pen
].SetColour(REDS
[pen
] / 255.0,
194 delete[] m_PointGrid
;
197 void GfxCore::TryToFreeArrays()
199 // Free up any memory allocated for arrays.
200 delete[] m_LabelGrid
;
205 // Initialisation methods
208 void GfxCore::Initialise(bool same_file
)
210 // Initialise the view from the parent holding the survey data.
214 m_DoneFirstShow
= false;
216 m_HitTestGridValid
= false;
220 m_MouseOutsideCompass
= m_MouseOutsideElev
= false;
223 // Apply default parameters unless reloading the same file.
229 // Clear any cached OpenGL lists which depend on the data.
230 InvalidateList(LIST_SCALE_BAR
);
231 InvalidateList(LIST_DEPTH_KEY
);
232 InvalidateList(LIST_DATE_KEY
);
233 InvalidateList(LIST_ERROR_KEY
);
234 InvalidateList(LIST_GRADIENT_KEY
);
235 InvalidateList(LIST_LENGTH_KEY
);
236 InvalidateList(LIST_UNDERGROUND_LEGS
);
237 InvalidateList(LIST_TUBES
);
238 InvalidateList(LIST_SURFACE_LEGS
);
239 InvalidateList(LIST_BLOBS
);
240 InvalidateList(LIST_CROSSES
);
241 InvalidateList(LIST_GRID
);
242 InvalidateList(LIST_SHADOW
);
243 InvalidateList(LIST_TERRAIN
);
245 // Set diameter of the viewing volume.
246 double cave_diameter
= sqrt(sqrd(m_Parent
->GetXExtent()) +
247 sqrd(m_Parent
->GetYExtent()) +
248 sqrd(m_Parent
->GetZExtent()));
250 // Allow for terrain.
251 double diameter
= max(1000.0 * 2, cave_diameter
* 2);
254 SetVolumeDiameter(diameter
);
256 // Set initial scale based on the size of the cave.
257 initial_scale
= diameter
/ cave_diameter
;
258 SetScale(initial_scale
);
260 // Adjust the position when restricting the view to a subsurvey (or
261 // expanding the view to show the whole survey).
262 AddTranslation(m_Parent
->GetOffset() - offsets
);
264 // Try to keep the same scale, allowing for the
265 // cave having grown (or shrunk).
266 double rescale
= GetVolumeDiameter() / diameter
;
267 SetVolumeDiameter(diameter
);
268 SetScale(GetScale() / rescale
); // ?
269 initial_scale
= initial_scale
* rescale
;
272 offsets
= m_Parent
->GetOffset();
277 void GfxCore::FirstShow()
279 GLACanvas::FirstShow();
281 const unsigned int quantise(GetFontSize() / QUANTISE_FACTOR
);
282 list
<LabelInfo
*>::iterator pos
= m_Parent
->GetLabelsNC();
283 while (pos
!= m_Parent
->GetLabelsNCEnd()) {
284 LabelInfo
* label
= *pos
++;
285 // Calculate and set the label width for use when plotting
286 // none-overlapping labels.
288 GLACanvas::GetTextExtent(label
->GetText(), &ext_x
, NULL
);
289 label
->set_width(unsigned(ext_x
) / quantise
+ 1);
292 m_DoneFirstShow
= true;
296 // Recalculating methods
299 void GfxCore::SetScale(Double scale
)
303 } else if (scale
> GetVolumeDiameter()) {
304 scale
= GetVolumeDiameter();
308 m_HitTestGridValid
= false;
309 if (m_here
&& m_here
== &temp_here
) SetHere();
311 GLACanvas::SetScale(scale
);
314 bool GfxCore::HasUndergroundLegs() const
316 return m_Parent
->HasUndergroundLegs();
319 bool GfxCore::HasSplays() const
321 return m_Parent
->HasSplays();
324 bool GfxCore::HasDupes() const
326 return m_Parent
->HasDupes();
329 bool GfxCore::HasSurfaceLegs() const
331 return m_Parent
->HasSurfaceLegs();
334 bool GfxCore::HasTubes() const
336 return m_Parent
->HasTubes();
339 void GfxCore::UpdateBlobs()
341 InvalidateList(LIST_BLOBS
);
348 void GfxCore::OnLeaveWindow(wxMouseEvent
&) {
353 void GfxCore::OnIdle(wxIdleEvent
& event
)
355 // Handle an idle event.
358 // If still animating, we want more idle events.
362 // If we're idle, don't show a bogus FPS next time we render.
367 void GfxCore::OnPaint(wxPaintEvent
&)
369 // Redraw the window.
371 // Get a graphics context.
375 // Make sure we're initialised.
376 bool first_time
= !m_DoneFirstShow
;
383 // Clear the background.
386 // Set up model transformation matrix.
389 if (m_Legs
|| m_Tubes
) {
391 EnableSmoothPolygons(true); // FIXME: allow false for wireframe view
392 DrawList(LIST_TUBES
);
393 DisableSmoothPolygons();
396 // Draw the underground legs. Do this last so that anti-aliasing
397 // works over polygons.
398 SetColour(col_GREEN
);
399 DrawList(LIST_UNDERGROUND_LEGS
);
403 // Draw the surface legs.
404 DrawList(LIST_SURFACE_LEGS
);
408 DrawShadowedBoundingBox();
415 DrawList(LIST_BLOBS
);
418 DrawList(LIST_CROSSES
);
422 // This is needed if blobs and/or crosses are drawn using lines -
423 // otherwise the terrain doesn't appear when they are enabled.
426 // We don't want to be able to see the terrain through itself, so
427 // do a "Z-prepass" - plot the terrain once only updating the
428 // Z-buffer, then again with Z-clipping only plotting where the
429 // depth matches the value in the Z-buffer.
430 DrawListZPrepass(LIST_TERRAIN
);
433 SetIndicatorTransform();
435 // Draw station names.
436 if (m_Names
/*&& !m_Control->MouseDown() && !Animating()*/) {
437 SetColour(NAME_COLOUR
);
439 if (m_OverlappingNames
) {
446 if (m_HitTestDebug
) {
447 // Show the hit test grid bucket sizes...
448 SetColour(m_HitTestGridValid
? col_LIGHT_GREY
: col_DARK_GREY
);
450 for (int i
= 0; i
!= HITTEST_SIZE
; ++i
) {
451 int x
= (GetXSize() + 1) * i
/ HITTEST_SIZE
+ 2;
452 for (int j
= 0; j
!= HITTEST_SIZE
; ++j
) {
453 int square
= i
+ j
* HITTEST_SIZE
;
454 unsigned long bucket_size
= m_PointGrid
[square
].size();
456 int y
= (GetYSize() + 1) * (HITTEST_SIZE
- 1 - j
) / HITTEST_SIZE
;
457 DrawIndicatorText(x
, y
, wxString::Format(wxT("%lu"), bucket_size
));
465 for (int i
= 0; i
!= HITTEST_SIZE
; ++i
) {
466 int x
= (GetXSize() + 1) * i
/ HITTEST_SIZE
;
467 PlaceIndicatorVertex(x
, 0);
468 PlaceIndicatorVertex(x
, GetYSize());
470 for (int j
= 0; j
!= HITTEST_SIZE
; ++j
) {
471 int y
= (GetYSize() + 1) * (HITTEST_SIZE
- 1 - j
) / HITTEST_SIZE
;
472 PlaceIndicatorVertex(0, y
);
473 PlaceIndicatorVertex(GetXSize(), y
);
476 DisableDashedLines();
479 long now
= timer
.Time();
481 // Show stats about rendering.
482 SetColour(col_TURQUOISE
);
483 int y
= GetYSize() - GetFontSize();
484 if (last_time
!= 0.0) {
485 // timer.Time() measure in milliseconds.
486 double fps
= 1000.0 / (now
- last_time
);
487 DrawIndicatorText(1, y
, wxString::Format(wxT("FPS:% 5.1f"), fps
));
490 DrawIndicatorText(1, y
, wxString::Format(wxT("▲:%lu"), (unsigned long)n_tris
));
496 // There's no advantage in generating an OpenGL list for the
497 // indicators since they change with almost every redraw (and
498 // sometimes several times between redraws). This way we avoid
499 // the need to track when to update the indicator OpenGL list,
500 // and also avoid indicator update bugs when we don't quite get this
504 if (zoombox
.active()) {
505 SetColour(SEL_COLOUR
);
508 glaCoord Y
= GetYSize();
509 PlaceIndicatorVertex(zoombox
.x1
, Y
- zoombox
.y1
);
510 PlaceIndicatorVertex(zoombox
.x1
, Y
- zoombox
.y2
);
511 PlaceIndicatorVertex(zoombox
.x2
, Y
- zoombox
.y2
);
512 PlaceIndicatorVertex(zoombox
.x2
, Y
- zoombox
.y1
);
513 PlaceIndicatorVertex(zoombox
.x1
, Y
- zoombox
.y1
);
515 DisableDashedLines();
516 } else if (MeasuringLineActive()) {
517 // Draw "here" and "there".
519 SetColour(HERE_COLOUR
);
522 Transform(*m_here
, &hx
, &hy
, &dummy
);
523 if (m_here
!= &temp_here
) DrawRing(hx
, hy
);
528 Transform(*m_there
, &tx
, &ty
, &dummy
);
531 PlaceIndicatorVertex(hx
, hy
);
532 PlaceIndicatorVertex(tx
, ty
);
543 dc
.SetBackground(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWFRAME
));
548 void GfxCore::DrawBoundingBox()
550 const Vector3 v
= 0.5 * m_Parent
->GetExtent();
555 PlaceVertex(-v
.GetX(), -v
.GetY(), v
.GetZ());
556 PlaceVertex(-v
.GetX(), v
.GetY(), v
.GetZ());
557 PlaceVertex(v
.GetX(), v
.GetY(), v
.GetZ());
558 PlaceVertex(v
.GetX(), -v
.GetY(), v
.GetZ());
559 PlaceVertex(-v
.GetX(), -v
.GetY(), v
.GetZ());
562 PlaceVertex(-v
.GetX(), -v
.GetY(), -v
.GetZ());
563 PlaceVertex(-v
.GetX(), v
.GetY(), -v
.GetZ());
564 PlaceVertex(v
.GetX(), v
.GetY(), -v
.GetZ());
565 PlaceVertex(v
.GetX(), -v
.GetY(), -v
.GetZ());
566 PlaceVertex(-v
.GetX(), -v
.GetY(), -v
.GetZ());
569 PlaceVertex(-v
.GetX(), -v
.GetY(), v
.GetZ());
570 PlaceVertex(-v
.GetX(), -v
.GetY(), -v
.GetZ());
571 PlaceVertex(-v
.GetX(), v
.GetY(), v
.GetZ());
572 PlaceVertex(-v
.GetX(), v
.GetY(), -v
.GetZ());
573 PlaceVertex(v
.GetX(), v
.GetY(), v
.GetZ());
574 PlaceVertex(v
.GetX(), v
.GetY(), -v
.GetZ());
575 PlaceVertex(v
.GetX(), -v
.GetY(), v
.GetZ());
576 PlaceVertex(v
.GetX(), -v
.GetY(), -v
.GetZ());
578 DisableDashedLines();
581 void GfxCore::DrawShadowedBoundingBox()
583 const Vector3 v
= 0.5 * m_Parent
->GetExtent();
588 SetColour(col_DARK_GREY
);
589 BeginQuadrilaterals();
590 PlaceVertex(-v
.GetX(), -v
.GetY(), -v
.GetZ());
591 PlaceVertex(-v
.GetX(), v
.GetY(), -v
.GetZ());
592 PlaceVertex(v
.GetX(), v
.GetY(), -v
.GetZ());
593 PlaceVertex(v
.GetX(), -v
.GetY(), -v
.GetZ());
595 PolygonOffset(false);
597 DrawList(LIST_SHADOW
);
600 void GfxCore::DrawGrid()
605 // Calculate the extent of the survey, in metres across the screen plane.
606 Double m_across_screen
= SurveyUnitsAcrossViewport();
607 // Calculate the length of the scale bar in metres.
608 //--move this elsewhere
609 Double size_snap
= pow(10.0, floor(log10(0.75 * m_across_screen
)));
610 Double t
= m_across_screen
* 0.75 / size_snap
;
618 Double grid_size
= size_snap
* 0.1;
619 Double edge
= grid_size
* 2.0;
620 Double grid_z
= -m_Parent
->GetZExtent() * 0.5 - grid_size
;
621 Double left
= -m_Parent
->GetXExtent() * 0.5 - edge
;
622 Double right
= m_Parent
->GetXExtent() * 0.5 + edge
;
623 Double bottom
= -m_Parent
->GetYExtent() * 0.5 - edge
;
624 Double top
= m_Parent
->GetYExtent() * 0.5 + edge
;
625 int count_x
= (int) ceil((right
- left
) / grid_size
);
626 int count_y
= (int) ceil((top
- bottom
) / grid_size
);
627 Double actual_right
= left
+ count_x
*grid_size
;
628 Double actual_top
= bottom
+ count_y
*grid_size
;
632 for (int xc
= 0; xc
<= count_x
; xc
++) {
633 Double x
= left
+ xc
*grid_size
;
635 PlaceVertex(x
, bottom
, grid_z
);
636 PlaceVertex(x
, actual_top
, grid_z
);
639 for (int yc
= 0; yc
<= count_y
; yc
++) {
640 Double y
= bottom
+ yc
*grid_size
;
641 PlaceVertex(left
, y
, grid_z
);
642 PlaceVertex(actual_right
, y
, grid_z
);
648 int GfxCore::GetClinoOffset() const
650 int result
= INDICATOR_OFFSET_X
;
652 result
+= 6 + GetCompassWidth() + INDICATOR_GAP
;
657 void GfxCore::DrawTick(int angle_cw
)
659 const Double theta
= rad(angle_cw
);
660 const wxCoord length1
= INDICATOR_RADIUS
;
661 const wxCoord length0
= length1
+ TICK_LENGTH
;
662 wxCoord x0
= wxCoord(length0
* sin(theta
));
663 wxCoord y0
= wxCoord(length0
* cos(theta
));
664 wxCoord x1
= wxCoord(length1
* sin(theta
));
665 wxCoord y1
= wxCoord(length1
* cos(theta
));
667 PlaceIndicatorVertex(x0
, y0
);
668 PlaceIndicatorVertex(x1
, y1
);
671 void GfxCore::DrawArrow(gla_colour col1
, gla_colour col2
) {
672 Vector3
p1(0, INDICATOR_RADIUS
, 0);
673 Vector3
p2(INDICATOR_RADIUS
/2, INDICATOR_RADIUS
*-.866025404, 0); // 150deg
674 Vector3
p3(-INDICATOR_RADIUS
/2, INDICATOR_RADIUS
*-.866025404, 0); // 210deg
677 DrawTriangle(col_LIGHT_GREY
, col1
, p2
, p1
, pc
);
678 DrawTriangle(col_LIGHT_GREY
, col2
, p3
, p1
, pc
);
681 void GfxCore::DrawCompass() {
684 for (int angle
= 315; angle
> 0; angle
-= 45) {
687 SetColour(col_GREEN
);
691 // Compass background.
692 DrawCircle(col_LIGHT_GREY_2
, col_GREY
, 0, 0, INDICATOR_RADIUS
);
695 DrawArrow(col_INDICATOR_1
, col_INDICATOR_2
);
698 // Draw the non-rotating background to the clino.
699 void GfxCore::DrawClinoBack() {
701 for (int angle
= 0; angle
<= 180; angle
+= 90) {
706 PlaceIndicatorVertex(0, INDICATOR_RADIUS
);
707 PlaceIndicatorVertex(0, -INDICATOR_RADIUS
);
708 PlaceIndicatorVertex(0, 0);
709 PlaceIndicatorVertex(INDICATOR_RADIUS
, 0);
714 void GfxCore::DrawClino() {
716 SetColour(col_GREEN
);
722 DrawSemicircle(col_LIGHT_GREY_2
, col_GREY
, 0, 0, INDICATOR_RADIUS
, 0);
725 DrawArrow(col_INDICATOR_2
, col_INDICATOR_1
);
728 void GfxCore::Draw2dIndicators()
730 // Draw the compass and elevation indicators.
732 const int centre_y
= INDICATOR_BOX_SIZE
/ 2 + INDICATOR_OFFSET_Y
;
734 const int comp_centre_x
= GetCompassXPosition();
736 if (m_Compass
&& !m_Parent
->IsExtendedElevation()) {
737 // If the user is dragging the compass with the pointer outside the
738 // compass, we snap to 45 degree multiples, and the ticks go white.
739 SetColour(m_MouseOutsideCompass
? col_WHITE
: col_LIGHT_GREY_2
);
740 DrawList2D(LIST_COMPASS
, comp_centre_x
, centre_y
, -m_PanAngle
);
743 const int elev_centre_x
= GetClinoXPosition();
746 // If the user is dragging the clino with the pointer outside the
747 // clino, we snap to 90 degree multiples, and the ticks go white.
748 SetColour(m_MouseOutsideElev
? col_WHITE
: col_LIGHT_GREY_2
);
749 DrawList2D(LIST_CLINO_BACK
, elev_centre_x
, centre_y
, 0);
750 DrawList2D(LIST_CLINO
, elev_centre_x
, centre_y
, 90 - m_TiltAngle
);
753 SetColour(TEXT_COLOUR
);
755 static int triple_zero_width
= 0;
756 static int height
= 0;
757 if (!triple_zero_width
) {
758 GetTextExtent(wxT("000"), &triple_zero_width
, &height
);
760 const int y_off
= INDICATOR_OFFSET_Y
+ INDICATOR_BOX_SIZE
+ height
/ 2;
762 if (m_Compass
&& !m_Parent
->IsExtendedElevation()) {
767 value
= int(m_PanAngle
);
768 /* TRANSLATORS: degree symbol - probably should be translated to
772 value
= int(m_PanAngle
* 200.0 / 180.0);
773 /* TRANSLATORS: symbol for grad (400 grad = 360 degrees = full
777 str
.Printf(wxT("%03d"), value
);
778 str
+= wmsg(brg_unit
);
779 DrawIndicatorText(comp_centre_x
- triple_zero_width
/ 2, y_off
, str
);
781 // TRANSLATORS: Used in aven above the compass indicator at the lower
782 // right of the display, with a bearing below "Facing". This indicates the
783 // direction the viewer is "facing" in.
785 // Try to keep this translation short - ideally at most 10 characters -
786 // as otherwise the compass and clino will be moved further apart to
788 str
= wmsg(/*Facing*/203);
790 GetTextExtent(str
, &w
, NULL
);
791 DrawIndicatorText(comp_centre_x
- w
/ 2, y_off
+ height
, str
);
795 if (m_TiltAngle
== -90.0) {
796 // TRANSLATORS: Label used for "clino" in Aven when the view is
797 // from directly above.
799 // Try to keep this translation short - ideally at most 10
800 // characters - as otherwise the compass and clino will be moved
801 // further apart to make room. */
802 wxString str
= wmsg(/*Plan*/432);
803 static int width
= 0;
805 GetTextExtent(str
, &width
, NULL
);
807 int x
= elev_centre_x
- width
/ 2;
808 DrawIndicatorText(x
, y_off
+ height
/ 2, str
);
809 } else if (m_TiltAngle
== 90.0) {
810 // TRANSLATORS: Label used for "clino" in Aven when the view is
811 // from directly below.
813 // Try to keep this translation short - ideally at most 10
814 // characters - as otherwise the compass and clino will be moved
815 // further apart to make room. */
816 wxString str
= wmsg(/*Kiwi Plan*/433);
817 static int width
= 0;
819 GetTextExtent(str
, &width
, NULL
);
821 int x
= elev_centre_x
- width
/ 2;
822 DrawIndicatorText(x
, y_off
+ height
/ 2, str
);
829 static int zero_width
= 0;
831 GetTextExtent(wxT("0"), &zero_width
, NULL
);
834 if (m_TiltAngle
> 89.99) {
836 } else if (m_TiltAngle
< -89.99) {
839 angle
= int(100 * tan(rad(m_TiltAngle
)));
841 if (angle
> 99999 || angle
< -99999) {
842 str
= angle
> 0 ? wxT("+") : wxT("-");
843 /* TRANSLATORS: infinity symbol - used for the percentage gradient on
844 * vertical angles. */
845 str
+= wmsg(/*∞*/431);
847 str
= angle
? wxString::Format(wxT("%+03d"), angle
) : wxT("0");
849 /* TRANSLATORS: symbol for percentage gradient (100% = 45
850 * degrees = 50 grad). */
852 } else if (m_Degrees
) {
853 static int zero_zero_width
= 0;
854 if (!zero_zero_width
) {
855 GetTextExtent(wxT("00"), &zero_zero_width
, NULL
);
857 width
= zero_zero_width
;
858 angle
= int(m_TiltAngle
);
859 str
= angle
? wxString::Format(wxT("%+03d"), angle
) : wxT("00");
862 width
= triple_zero_width
;
863 angle
= int(m_TiltAngle
* 200.0 / 180.0);
864 str
= angle
? wxString::Format(wxT("%+04d"), angle
) : wxT("000");
869 if (unit
== /*%*/96) {
870 // Right align % since the width changes so much.
871 GetTextExtent(str
, &sign_offset
, NULL
);
872 sign_offset
-= width
;
873 } else if (angle
< 0) {
874 // Adjust horizontal position so the left of the first digit is
875 // always in the same place.
876 static int minus_width
= 0;
878 GetTextExtent(wxT("-"), &minus_width
, NULL
);
880 sign_offset
= minus_width
;
881 } else if (angle
> 0) {
882 // Adjust horizontal position so the left of the first digit is
883 // always in the same place.
884 static int plus_width
= 0;
886 GetTextExtent(wxT("+"), &plus_width
, NULL
);
888 sign_offset
= plus_width
;
892 DrawIndicatorText(elev_centre_x
- sign_offset
- width
/ 2, y_off
, str
);
894 // TRANSLATORS: Label used for "clino" in Aven when the view is
895 // neither from directly above nor from directly below. It is
896 // also used in the dialog for editing a marked position in a
899 // Try to keep this translation short - ideally at most 10
900 // characters - as otherwise the compass and clino will be moved
901 // further apart to make room. */
902 str
= wmsg(/*Elevation*/118);
903 static int elevation_width
= 0;
904 if (!elevation_width
) {
905 GetTextExtent(str
, &elevation_width
, NULL
);
907 int x
= elev_centre_x
- elevation_width
/ 2;
908 DrawIndicatorText(x
, y_off
+ height
, str
);
913 void GfxCore::NattyDrawNames()
915 // Draw station names, without overlapping.
917 const unsigned int quantise(GetFontSize() / QUANTISE_FACTOR
);
918 const unsigned int quantised_x
= GetXSize() / quantise
;
919 const unsigned int quantised_y
= GetYSize() / quantise
;
920 const size_t buffer_size
= quantised_x
* quantised_y
;
922 if (!m_LabelGrid
) m_LabelGrid
= new char[buffer_size
];
924 memset((void*) m_LabelGrid
, 0, buffer_size
);
926 list
<LabelInfo
*>::const_iterator label
= m_Parent
->GetLabels();
927 for ( ; label
!= m_Parent
->GetLabelsEnd(); ++label
) {
928 if (!((m_Surface
&& (*label
)->IsSurface()) ||
929 (m_Legs
&& (*label
)->IsUnderground()) ||
930 (!(*label
)->IsSurface() && !(*label
)->IsUnderground()))) {
931 // if this station isn't to be displayed, skip to the next
932 // (last case is for stns with no legs attached)
938 Transform(**label
, &x
, &y
, &z
);
939 // Check if the label is behind us (in perspective view).
940 if (z
<= 0.0 || z
>= 1.0) continue;
942 // Apply a small shift so that translating the view doesn't make which
943 // labels are displayed change as the resulting twinkling effect is
946 Transform(Vector3(), &tx
, &ty
, &tz
);
947 tx
-= floor(tx
/ quantise
) * quantise
;
948 ty
-= floor(ty
/ quantise
) * quantise
;
951 if (tx
< 0) continue;
954 if (ty
< 0) continue;
956 unsigned int iy
= unsigned(ty
) / quantise
;
957 if (iy
>= quantised_y
) continue;
958 unsigned int width
= (*label
)->get_width();
959 unsigned int ix
= unsigned(tx
) / quantise
;
960 if (ix
+ width
>= quantised_x
) continue;
962 char * test
= m_LabelGrid
+ ix
+ iy
* quantised_x
;
963 if (memchr(test
, 1, width
)) continue;
966 y
-= GetFontSize() / 2;
967 DrawIndicatorText((int)x
, (int)y
, (*label
)->GetText());
969 if (iy
> QUANTISE_FACTOR
) iy
= QUANTISE_FACTOR
;
970 test
-= quantised_x
* iy
;
972 while (--iy
&& test
< m_LabelGrid
+ buffer_size
) {
973 memset(test
, 1, width
);
979 void GfxCore::SimpleDrawNames()
981 // Draw all station names, without worrying about overlaps
982 list
<LabelInfo
*>::const_iterator label
= m_Parent
->GetLabels();
983 for ( ; label
!= m_Parent
->GetLabelsEnd(); ++label
) {
984 if (!((m_Surface
&& (*label
)->IsSurface()) ||
985 (m_Legs
&& (*label
)->IsUnderground()) ||
986 (!(*label
)->IsSurface() && !(*label
)->IsUnderground()))) {
987 // if this station isn't to be displayed, skip to the next
988 // (last case is for stns with no legs attached)
993 Transform(**label
, &x
, &y
, &z
);
995 // Check if the label is behind us (in perspective view).
996 if (z
<= 0) continue;
999 y
-= GetFontSize() / 2;
1000 DrawIndicatorText((int)x
, (int)y
, (*label
)->GetText());
1004 void GfxCore::DrawColourKey(int num_bands
, const wxString
& other
, const wxString
& units
)
1006 int total_block_height
=
1007 KEY_BLOCK_HEIGHT
* (num_bands
== 1 ? num_bands
: num_bands
- 1);
1008 if (!other
.empty()) total_block_height
+= KEY_BLOCK_HEIGHT
* 2;
1009 if (!units
.empty()) total_block_height
+= KEY_BLOCK_HEIGHT
;
1011 const int bottom
= -total_block_height
;
1014 if (!other
.empty()) GetTextExtent(other
, &size
, NULL
);
1016 for (band
= 0; band
< num_bands
; ++band
) {
1018 GetTextExtent(key_legends
[band
], &x
, NULL
);
1019 if (x
> size
) size
= x
;
1022 int left
= -KEY_BLOCK_WIDTH
- size
;
1024 key_lowerleft
[m_ColourBy
].x
= left
- KEY_EXTRA_LEFT_MARGIN
;
1025 key_lowerleft
[m_ColourBy
].y
= bottom
;
1028 if (!units
.empty()) y
+= KEY_BLOCK_HEIGHT
;
1030 if (!other
.empty()) {
1031 DrawShadedRectangle(GetSurfacePen(), GetSurfacePen(), left
, y
,
1032 KEY_BLOCK_WIDTH
, KEY_BLOCK_HEIGHT
);
1033 SetColour(col_BLACK
);
1035 PlaceIndicatorVertex(left
, y
);
1036 PlaceIndicatorVertex(left
+ KEY_BLOCK_WIDTH
, y
);
1037 PlaceIndicatorVertex(left
+ KEY_BLOCK_WIDTH
, y
+ KEY_BLOCK_HEIGHT
);
1038 PlaceIndicatorVertex(left
, y
+ KEY_BLOCK_HEIGHT
);
1039 PlaceIndicatorVertex(left
, y
);
1041 y
+= KEY_BLOCK_HEIGHT
* 2;
1045 if (num_bands
== 1) {
1046 DrawShadedRectangle(GetPen(0), GetPen(0), left
, y
,
1047 KEY_BLOCK_WIDTH
, KEY_BLOCK_HEIGHT
);
1048 y
+= KEY_BLOCK_HEIGHT
;
1050 for (band
= 0; band
< num_bands
- 1; ++band
) {
1051 DrawShadedRectangle(GetPen(band
), GetPen(band
+ 1), left
, y
,
1052 KEY_BLOCK_WIDTH
, KEY_BLOCK_HEIGHT
);
1053 y
+= KEY_BLOCK_HEIGHT
;
1057 SetColour(col_BLACK
);
1059 PlaceIndicatorVertex(left
, y
);
1060 PlaceIndicatorVertex(left
+ KEY_BLOCK_WIDTH
, y
);
1061 PlaceIndicatorVertex(left
+ KEY_BLOCK_WIDTH
, start
);
1062 PlaceIndicatorVertex(left
, start
);
1063 PlaceIndicatorVertex(left
, y
);
1066 SetColour(TEXT_COLOUR
);
1069 if (!units
.empty()) {
1070 GetTextExtent(units
, &size
, NULL
);
1071 DrawIndicatorText(left
+ (KEY_BLOCK_WIDTH
- size
) / 2, y
, units
);
1072 y
+= KEY_BLOCK_HEIGHT
;
1074 y
-= GetFontSize() / 2;
1075 left
+= KEY_BLOCK_WIDTH
+ 5;
1077 if (!other
.empty()) {
1078 y
+= KEY_BLOCK_HEIGHT
/ 2;
1079 DrawIndicatorText(left
, y
, other
);
1080 y
+= KEY_BLOCK_HEIGHT
* 2 - KEY_BLOCK_HEIGHT
/ 2;
1083 if (num_bands
== 1) {
1084 y
+= KEY_BLOCK_HEIGHT
/ 2;
1085 DrawIndicatorText(left
, y
, key_legends
[0]);
1087 for (band
= 0; band
< num_bands
; ++band
) {
1088 DrawIndicatorText(left
, y
, key_legends
[band
]);
1089 y
+= KEY_BLOCK_HEIGHT
;
1094 void GfxCore::DrawDepthKey()
1096 Double z_ext
= m_Parent
->GetDepthExtent();
1100 num_bands
= GetNumColourBands();
1101 Double z_range
= z_ext
;
1102 if (!m_Metric
) z_range
/= METRES_PER_FOOT
;
1103 sf
= max(0, 1 - (int)floor(log10(z_range
)));
1106 Double z_min
= m_Parent
->GetDepthMin() + m_Parent
->GetOffset().GetZ();
1107 for (int band
= 0; band
< num_bands
; ++band
) {
1110 z
+= z_ext
* band
/ (num_bands
- 1);
1113 z
/= METRES_PER_FOOT
;
1115 key_legends
[band
].Printf(wxT("%.*f"), sf
, z
);
1118 DrawColourKey(num_bands
, wxString(), wmsg(m_Metric
? /*m*/424: /*ft*/428));
1121 void GfxCore::DrawDateKey()
1124 if (!HasDateInformation()) {
1127 int date_ext
= m_Parent
->GetDateExtent();
1128 if (date_ext
== 0) {
1131 num_bands
= GetNumColourBands();
1133 for (int band
= 0; band
< num_bands
; ++band
) {
1135 int days
= m_Parent
->GetDateMin();
1137 days
+= date_ext
* band
/ (num_bands
- 1);
1138 ymd_from_days_since_1900(days
, &y
, &m
, &d
);
1139 key_legends
[band
].Printf(wxT("%04d-%02d-%02d"), y
, m
, d
);
1144 if (!m_Parent
->HasCompleteDateInfo()) {
1145 /* TRANSLATORS: Used in the "colour key" for "colour by date" if there
1146 * are surveys without date information. Try to keep this fairly short.
1148 other
= wmsg(/*Undated*/221);
1151 DrawColourKey(num_bands
, other
, wxString());
1154 void GfxCore::DrawErrorKey()
1157 if (HasErrorInformation()) {
1158 // Use fixed colours for each error factor so it's directly visually
1159 // comparable between surveys.
1160 num_bands
= GetNumColourBands();
1161 for (int band
= 0; band
< num_bands
; ++band
) {
1162 double E
= MAX_ERROR
* band
/ (num_bands
- 1);
1163 key_legends
[band
].Printf(wxT("%.2f"), E
);
1169 // Always show the "Not in loop" legend for now (FIXME).
1170 /* TRANSLATORS: Used in the "colour key" for "colour by error" for surveys
1171 * which aren’t part of a loop and so have no error information. Try to keep
1172 * this fairly short. */
1173 DrawColourKey(num_bands
, wmsg(/*Not in loop*/290), wxString());
1176 void GfxCore::DrawGradientKey()
1179 // Use fixed colours for each gradient so it's directly visually comparable
1181 num_bands
= GetNumColourBands();
1182 wxString units
= wmsg(m_Degrees
? /*°*/344 : /*ᵍ*/345);
1183 for (int band
= 0; band
< num_bands
; ++band
) {
1184 double gradient
= double(band
) / (num_bands
- 1);
1190 key_legends
[band
].Printf(wxT("%.f%s"), gradient
, units
);
1193 DrawColourKey(num_bands
, wxString(), wxString());
1196 void GfxCore::DrawLengthKey()
1199 // Use fixed colours for each length so it's directly visually comparable
1201 num_bands
= GetNumColourBands();
1202 for (int band
= 0; band
< num_bands
; ++band
) {
1203 double len
= pow(10, LOG_LEN_MAX
* band
/ (num_bands
- 1));
1205 len
/= METRES_PER_FOOT
;
1207 key_legends
[band
].Printf(wxT("%.1f"), len
);
1210 DrawColourKey(num_bands
, wxString(), wmsg(m_Metric
? /*m*/424: /*ft*/428));
1213 void GfxCore::DrawScaleBar()
1215 // Draw the scalebar.
1216 if (GetPerspective()) return;
1218 // Calculate how many metres of survey are currently displayed across the
1220 Double across_screen
= SurveyUnitsAcrossViewport();
1222 double f
= double(GetClinoXPosition() - INDICATOR_BOX_SIZE
/ 2 - SCALE_BAR_OFFSET_X
) / GetXSize();
1225 } else if (f
< 0.5) {
1226 // Stop it getting squeezed to nothing.
1227 // FIXME: In this case we should probably move the compass and clino up
1228 // to make room rather than letting stuff overlap.
1232 // Convert to imperial measurements if required.
1233 Double multiplier
= 1.0;
1235 across_screen
/= METRES_PER_FOOT
;
1236 multiplier
= METRES_PER_FOOT
;
1237 if (across_screen
>= 5280.0 / f
) {
1238 across_screen
/= 5280.0;
1239 multiplier
*= 5280.0;
1243 // Calculate the length of the scale bar.
1244 Double size_snap
= pow(10.0, floor(log10(f
* across_screen
)));
1245 Double t
= across_screen
* f
/ size_snap
;
1248 } else if (t
>= 2.0) {
1252 if (!m_Metric
) size_snap
*= multiplier
;
1254 // Actual size of the thing in pixels:
1255 int size
= int((size_snap
/ SurveyUnitsAcrossViewport()) * GetXSize());
1256 m_ScaleBarWidth
= size
;
1259 const int end_y
= SCALE_BAR_OFFSET_Y
+ SCALE_BAR_HEIGHT
;
1260 int interval
= size
/ 10;
1262 gla_colour col
= col_WHITE
;
1263 for (int ix
= 0; ix
< 10; ix
++) {
1264 int x
= SCALE_BAR_OFFSET_X
+ int(ix
* ((Double
) size
/ 10.0));
1266 DrawRectangle(col
, col
, x
, end_y
, interval
+ 2, SCALE_BAR_HEIGHT
);
1268 col
= (col
== col_WHITE
) ? col_GREY
: col_WHITE
;
1275 Double km
= size_snap
* 1e-3;
1278 /* TRANSLATORS: abbreviation for "kilometres" (unit of length),
1281 * If there should be a space between the number and this, include
1282 * one in the translation. */
1284 } else if (size_snap
>= 1.0) {
1285 /* TRANSLATORS: abbreviation for "metres" (unit of length), used
1288 * If there should be a space between the number and this, include
1289 * one in the translation. */
1293 /* TRANSLATORS: abbreviation for "centimetres" (unit of length),
1296 * If there should be a space between the number and this, include
1297 * one in the translation. */
1301 size_snap
/= METRES_PER_FOOT
;
1302 Double miles
= size_snap
/ 5280.0;
1305 if (size_snap
>= 2.0) {
1306 /* TRANSLATORS: abbreviation for "miles" (unit of length,
1307 * plural), used e.g. "2 miles".
1309 * If there should be a space between the number and this,
1310 * include one in the translation. */
1311 units
= /* miles*/426;
1313 /* TRANSLATORS: abbreviation for "mile" (unit of length,
1314 * singular), used e.g. "1 mile".
1316 * If there should be a space between the number and this,
1317 * include one in the translation. */
1318 units
= /* mile*/427;
1320 } else if (size_snap
>= 1.0) {
1321 /* TRANSLATORS: abbreviation for "feet" (unit of length), used e.g.
1324 * If there should be a space between the number and this, include
1325 * one in the translation. */
1329 /* TRANSLATORS: abbreviation for "inches" (unit of length), used
1332 * If there should be a space between the number and this, include
1333 * one in the translation. */
1337 if (size_snap
>= 1.0) {
1338 str
.Printf(wxT("%.f%s"), size_snap
, wmsg(units
).c_str());
1340 int sf
= -(int)floor(log10(size_snap
));
1341 str
.Printf(wxT("%.*f%s"), sf
, size_snap
, wmsg(units
).c_str());
1344 int text_width
, text_height
;
1345 GetTextExtent(str
, &text_width
, &text_height
);
1346 const int text_y
= end_y
- text_height
+ 1;
1347 SetColour(TEXT_COLOUR
);
1348 DrawIndicatorText(SCALE_BAR_OFFSET_X
, text_y
, wxT("0"));
1349 DrawIndicatorText(SCALE_BAR_OFFSET_X
+ size
- text_width
, text_y
, str
);
1352 bool GfxCore::CheckHitTestGrid(const wxPoint
& point
, bool centre
)
1354 if (Animating()) return false;
1356 if (point
.x
< 0 || point
.x
>= GetXSize() ||
1357 point
.y
< 0 || point
.y
>= GetYSize()) {
1363 if (!m_HitTestGridValid
) CreateHitTestGrid();
1365 int grid_x
= point
.x
* HITTEST_SIZE
/ (GetXSize() + 1);
1366 int grid_y
= point
.y
* HITTEST_SIZE
/ (GetYSize() + 1);
1368 LabelInfo
*best
= NULL
;
1369 int dist_sqrd
= sqrd_measure_threshold
;
1370 int square
= grid_x
+ grid_y
* HITTEST_SIZE
;
1371 list
<LabelInfo
*>::iterator iter
= m_PointGrid
[square
].begin();
1373 while (iter
!= m_PointGrid
[square
].end()) {
1374 LabelInfo
*pt
= *iter
++;
1378 Transform(*pt
, &cx
, &cy
, &cz
);
1380 cy
= GetYSize() - cy
;
1382 int dx
= point
.x
- int(cx
);
1384 if (ds
>= dist_sqrd
) continue;
1385 int dy
= point
.y
- int(cy
);
1388 if (ds
>= dist_sqrd
) continue;
1397 m_Parent
->ShowInfo(best
, m_there
);
1399 // FIXME: allow Ctrl-Click to not set there or something?
1401 WarpPointer(GetXSize() / 2, GetYSize() / 2);
1403 m_Parent
->SelectTreeItem(best
);
1406 // Left-clicking not on a survey cancels the measuring line.
1408 ClearTreeSelection();
1410 m_Parent
->ShowInfo(best
, m_there
);
1412 ReverseTransform(point
.x
, GetYSize() - point
.y
, &x
, &y
, &z
);
1413 temp_here
.assign(Vector3(x
, y
, z
));
1414 SetHere(&temp_here
);
1421 void GfxCore::OnSize(wxSizeEvent
& event
)
1423 // Handle a change in window size.
1424 wxSize size
= event
.GetSize();
1426 if (size
.GetWidth() <= 0 || size
.GetHeight() <= 0) {
1427 // Before things are fully initialised, we sometimes get a bogus
1428 // resize message...
1429 // FIXME have changes in MainFrm cured this? It still happens with
1430 // 1.0.32 and wxGTK 2.5.2 (load a file from the command line).
1431 // With 1.1.6 and wxGTK 2.4.2 we only get negative sizes if MainFrm
1432 // is resized such that the GfxCore window isn't visible.
1433 //printf("OnSize(%d,%d)\n", size.GetWidth(), size.GetHeight());
1439 if (m_DoneFirstShow
) {
1442 m_HitTestGridValid
= false;
1448 void GfxCore::DefaultParameters()
1450 // Set default viewing parameters.
1453 if (!m_Parent
->HasUndergroundLegs()) {
1454 if (m_Parent
->HasSurfaceLegs()) {
1455 // If there are surface legs, but no underground legs, turn
1456 // surface surveys on.
1459 // If there are no legs (e.g. after loading a .pos file), turn
1466 if (m_Parent
->IsExtendedElevation()) {
1469 m_TiltAngle
= -90.0;
1472 SetRotation(m_PanAngle
, m_TiltAngle
);
1473 SetTranslation(Vector3());
1475 m_RotationStep
= 30.0;
1478 m_Entrances
= false;
1480 m_ExportedPts
= false;
1482 m_BoundingBox
= false;
1484 if (GetPerspective()) TogglePerspective();
1486 // Set the initial scale.
1487 SetScale(initial_scale
);
1490 void GfxCore::Defaults()
1492 // Restore default scale, rotation and translation parameters.
1493 DefaultParameters();
1495 // Invalidate all the cached lists.
1496 GLACanvas::FirstShow();
1501 void GfxCore::Animate()
1503 // Don't show pointer coordinates while animating.
1504 // FIXME : only do this when we *START* animating! Use a static copy
1505 // of the value of "Animating()" last time we were here to track this?
1506 // MainFrm now checks if we're trying to clear already cleared labels
1507 // and just returns, but it might be simpler to check here!
1509 m_Parent
->ShowInfo();
1513 ReadPixels(movie
->GetWidth(), movie
->GetHeight(), movie
->GetBuffer());
1514 if (!movie
->AddFrame()) {
1515 wxGetApp().ReportError(wxString(movie
->get_error_string(), wxConvUTF8
));
1518 presentation_mode
= 0;
1521 t
= 1000 / 25; // 25 frames per second
1523 static long t_prev
= 0;
1525 // Avoid redrawing twice in the same frame.
1526 long delta_t
= (t_prev
== 0 ? 1000 / MAX_FRAMERATE
: t
- t_prev
);
1527 if (delta_t
< 1000 / MAX_FRAMERATE
)
1530 if (presentation_mode
== PLAYING
&& pres_speed
!= 0.0)
1534 if (presentation_mode
== PLAYING
&& pres_speed
!= 0.0) {
1535 // FIXME: It would probably be better to work relative to the time we
1536 // passed the last mark, but that's complicated by the speed
1537 // potentially changing (or even the direction of playback reversing)
1538 // at any point during playback.
1539 Double tick
= t
* 0.001 * fabs(pres_speed
);
1540 while (tick
>= next_mark_time
) {
1541 tick
-= next_mark_time
;
1542 this_mark_total
= 0;
1543 PresentationMark prev_mark
= next_mark
;
1544 if (prev_mark
.angle
< 0) prev_mark
.angle
+= 360.0;
1545 else if (prev_mark
.angle
>= 360.0) prev_mark
.angle
-= 360.0;
1547 next_mark
= m_Parent
->GetPresMark(MARK_PREV
);
1549 next_mark
= m_Parent
->GetPresMark(MARK_NEXT
);
1550 if (!next_mark
.is_valid()) {
1552 presentation_mode
= 0;
1553 if (movie
&& !movie
->Close()) {
1554 wxGetApp().ReportError(wxString(movie
->get_error_string(), wxConvUTF8
));
1561 double tmp
= (pres_reverse
? prev_mark
.time
: next_mark
.time
);
1563 next_mark_time
= tmp
;
1565 double d
= (next_mark
- prev_mark
).magnitude();
1566 // FIXME: should ignore component of d which is unseen in
1567 // non-perspective mode?
1568 next_mark_time
= sqrd(d
/ 30.0);
1569 double a
= next_mark
.angle
- prev_mark
.angle
;
1571 next_mark
.angle
-= 360.0;
1573 } else if (a
< -180.0) {
1574 next_mark
.angle
+= 360.0;
1579 next_mark_time
+= sqrd(a
/ 60.0);
1580 double ta
= fabs(next_mark
.tilt_angle
- prev_mark
.tilt_angle
);
1581 next_mark_time
+= sqrd(ta
/ 60.0);
1582 double s
= fabs(log(next_mark
.scale
) - log(prev_mark
.scale
));
1583 next_mark_time
+= sqrd(s
/ 2.0);
1584 next_mark_time
= sqrt(next_mark_time
);
1585 // was: next_mark_time = max(max(d / 30, s / 2), max(a, ta) / 60);
1586 //printf("*** %.6f from (\nd: %.6f\ns: %.6f\na: %.6f\nt: %.6f )\n",
1587 // next_mark_time, d/30.0, s/2.0, a/60.0, ta/60.0);
1588 if (tmp
< 0) next_mark_time
/= -tmp
;
1592 if (presentation_mode
) {
1593 // Advance position towards next_mark
1594 double p
= tick
/ next_mark_time
;
1596 PresentationMark here
= GetView();
1597 if (next_mark
.angle
< 0) {
1598 if (here
.angle
>= next_mark
.angle
+ 360.0)
1599 here
.angle
-= 360.0;
1600 } else if (next_mark
.angle
>= 360.0) {
1601 if (here
.angle
<= next_mark
.angle
- 360.0)
1602 here
.angle
+= 360.0;
1604 here
.assign(q
* here
+ p
* next_mark
);
1605 here
.angle
= q
* here
.angle
+ p
* next_mark
.angle
;
1606 if (here
.angle
< 0) here
.angle
+= 360.0;
1607 else if (here
.angle
>= 360.0) here
.angle
-= 360.0;
1608 here
.tilt_angle
= q
* here
.tilt_angle
+ p
* next_mark
.tilt_angle
;
1609 here
.scale
= exp(q
* log(here
.scale
) + p
* log(next_mark
.scale
));
1611 this_mark_total
+= tick
;
1612 next_mark_time
-= tick
;
1621 Double step
= base_pan
+ (t
- base_pan_time
) * 1e-3 * m_RotationStep
- m_PanAngle
;
1625 if (m_SwitchingTo
== PLAN
) {
1626 // When switching to plan view...
1627 Double step
= base_tilt
- (t
- base_tilt_time
) * 1e-3 * 90.0 - m_TiltAngle
;
1629 if (m_TiltAngle
== -90.0) {
1632 } else if (m_SwitchingTo
== ELEVATION
) {
1633 // When switching to elevation view...
1635 if (m_TiltAngle
> 0.0) {
1636 step
= base_tilt
- (t
- base_tilt_time
) * 1e-3 * 90.0 - m_TiltAngle
;
1638 step
= base_tilt
+ (t
- base_tilt_time
) * 1e-3 * 90.0 - m_TiltAngle
;
1640 if (fabs(step
) >= fabs(m_TiltAngle
)) {
1642 step
= -m_TiltAngle
;
1645 } else if (m_SwitchingTo
) {
1646 // Rotate the shortest way around to the destination angle. If we're
1647 // 180 off, we favour turning anticlockwise, as auto-rotation does by
1649 Double target
= (m_SwitchingTo
- NORTH
) * 90;
1650 Double diff
= target
- m_PanAngle
;
1651 diff
= fmod(diff
, 360);
1654 else if (diff
> 180)
1656 if (m_RotationStep
< 0 && diff
== 180.0)
1658 Double step
= base_pan
- m_PanAngle
;
1659 Double delta
= (t
- base_pan_time
) * 1e-3 * fabs(m_RotationStep
);
1665 step
= fmod(step
, 360);
1668 else if (step
> 180)
1670 if (fabs(step
) >= fabs(diff
)) {
1680 // How much to allow around the box - this is because of the ring shape
1681 // at one end of the line.
1682 static const int HIGHLIGHTED_PT_SIZE
= 2; // FIXME: tie in to blob and ring size
1683 #define MARGIN (HIGHLIGHTED_PT_SIZE * 2 + 1)
1684 void GfxCore::RefreshLine(const Point
*a
, const Point
*b
, const Point
*c
)
1690 // FIXME: We get odd redraw artifacts if we just update the line, and
1691 // redrawing the whole scene doesn't actually seem to be measurably
1692 // slower. That may not be true with software rendering though...
1695 // Best of all might be to copy the window contents before we draw the
1696 // line, then replace each time we redraw.
1698 // Calculate the minimum rectangle which includes the old and new
1699 // measuring lines to minimise the redraw time
1700 int l
= INT_MAX
, r
= INT_MIN
, u
= INT_MIN
, d
= INT_MAX
;
1703 if (!Transform(*a
, &X
, &Y
, &Z
)) {
1707 int y
= GetYSize() - 1 - int(Y
);
1715 if (!Transform(*b
, &X
, &Y
, &Z
)) {
1719 int y
= GetYSize() - 1 - int(Y
);
1727 if (!Transform(*c
, &X
, &Y
, &Z
)) {
1731 int y
= GetYSize() - 1 - int(Y
);
1742 RefreshRect(wxRect(l
, d
, r
- l
, u
- d
), false);
1746 void GfxCore::SetHereFromTree(const LabelInfo
* p
)
1749 m_Parent
->ShowInfo(m_here
, m_there
);
1752 void GfxCore::SetHere(const LabelInfo
*p
)
1754 if (p
== m_here
) return;
1755 bool line_active
= MeasuringLineActive();
1756 const LabelInfo
* old
= m_here
;
1758 if (line_active
|| MeasuringLineActive())
1759 RefreshLine(old
, m_there
, m_here
);
1762 void GfxCore::SetThere(const LabelInfo
* p
)
1764 if (p
== m_there
) return;
1765 const LabelInfo
* old
= m_there
;
1767 RefreshLine(m_here
, old
, m_there
);
1770 void GfxCore::CreateHitTestGrid()
1773 // Initialise hit-test grid.
1774 m_PointGrid
= new list
<LabelInfo
*>[HITTEST_SIZE
* HITTEST_SIZE
];
1776 // Clear hit-test grid.
1777 for (int i
= 0; i
< HITTEST_SIZE
* HITTEST_SIZE
; i
++) {
1778 m_PointGrid
[i
].clear();
1783 list
<LabelInfo
*>::const_iterator pos
= m_Parent
->GetLabels();
1784 list
<LabelInfo
*>::const_iterator end
= m_Parent
->GetLabelsEnd();
1785 while (pos
!= end
) {
1786 LabelInfo
* label
= *pos
++;
1788 if (!((m_Surface
&& label
->IsSurface()) ||
1789 (m_Legs
&& label
->IsUnderground()) ||
1790 (!label
->IsSurface() && !label
->IsUnderground()))) {
1791 // if this station isn't to be displayed, skip to the next
1792 // (last case is for stns with no legs attached)
1796 // Calculate screen coordinates.
1798 Transform(*label
, &cx
, &cy
, &cz
);
1799 if (cx
< 0 || cx
>= GetXSize()) continue;
1800 if (cy
< 0 || cy
>= GetYSize()) continue;
1802 cy
= GetYSize() - cy
;
1804 // On-screen, so add to hit-test grid...
1805 int grid_x
= int(cx
* HITTEST_SIZE
/ (GetXSize() + 1));
1806 int grid_y
= int(cy
* HITTEST_SIZE
/ (GetYSize() + 1));
1808 m_PointGrid
[grid_x
+ grid_y
* HITTEST_SIZE
].push_back(label
);
1811 m_HitTestGridValid
= true;
1815 // Methods for controlling the orientation of the survey
1818 void GfxCore::TurnCave(Double angle
)
1820 // Turn the cave around its z-axis by a given angle.
1822 m_PanAngle
+= angle
;
1823 // Wrap to range [0, 360):
1824 m_PanAngle
= fmod(m_PanAngle
, 360.0);
1825 if (m_PanAngle
< 0.0) {
1826 m_PanAngle
+= 360.0;
1829 m_HitTestGridValid
= false;
1830 if (m_here
&& m_here
== &temp_here
) SetHere();
1832 SetRotation(m_PanAngle
, m_TiltAngle
);
1835 void GfxCore::TurnCaveTo(Double angle
)
1838 // If we're rotating, jump to the specified angle.
1839 TurnCave(angle
- m_PanAngle
);
1844 int new_switching_to
= ((int)angle
) / 90 + NORTH
;
1845 if (new_switching_to
== m_SwitchingTo
) {
1846 // A second order to switch takes us there right away
1847 TurnCave(angle
- m_PanAngle
);
1852 m_SwitchingTo
= new_switching_to
;
1856 void GfxCore::TiltCave(Double tilt_angle
)
1858 // Tilt the cave by a given angle.
1859 if (m_TiltAngle
+ tilt_angle
> 90.0) {
1861 } else if (m_TiltAngle
+ tilt_angle
< -90.0) {
1862 m_TiltAngle
= -90.0;
1864 m_TiltAngle
+= tilt_angle
;
1867 m_HitTestGridValid
= false;
1868 if (m_here
&& m_here
== &temp_here
) SetHere();
1870 SetRotation(m_PanAngle
, m_TiltAngle
);
1873 void GfxCore::TranslateCave(int dx
, int dy
)
1875 AddTranslationScreenCoordinates(dx
, dy
);
1876 m_HitTestGridValid
= false;
1878 if (m_here
&& m_here
== &temp_here
) SetHere();
1883 void GfxCore::DragFinished()
1885 m_MouseOutsideCompass
= m_MouseOutsideElev
= false;
1889 void GfxCore::ClearCoords()
1891 m_Parent
->ClearCoords();
1894 void GfxCore::SetCoords(wxPoint point
)
1896 // We can't work out 2D coordinates from a perspective view, and it
1897 // doesn't really make sense to show coordinates while we're animating.
1898 if (GetPerspective() || Animating()) return;
1900 // Update the coordinate or altitude display, given the (x, y) position in
1901 // window coordinates. The relevant display is updated depending on
1902 // whether we're in plan or elevation view.
1907 ReverseTransform(point
.x
, GetYSize() - 1 - point
.y
, &cx
, &cy
, &cz
);
1909 if (ShowingPlan()) {
1910 m_Parent
->SetCoords(cx
+ m_Parent
->GetOffset().GetX(),
1911 cy
+ m_Parent
->GetOffset().GetY(),
1913 } else if (ShowingElevation()) {
1914 m_Parent
->SetAltitude(cz
+ m_Parent
->GetOffset().GetZ(),
1917 m_Parent
->ClearCoords();
1921 int GfxCore::GetCompassWidth() const
1923 static int result
= 0;
1925 result
= INDICATOR_BOX_SIZE
;
1927 const wxString
& msg
= wmsg(/*Facing*/203);
1928 GetTextExtent(msg
, &width
, NULL
);
1929 if (width
> result
) result
= width
;
1934 int GfxCore::GetClinoWidth() const
1936 static int result
= 0;
1938 result
= INDICATOR_BOX_SIZE
;
1940 const wxString
& msg1
= wmsg(/*Plan*/432);
1941 GetTextExtent(msg1
, &width
, NULL
);
1942 if (width
> result
) result
= width
;
1943 const wxString
& msg2
= wmsg(/*Kiwi Plan*/433);
1944 GetTextExtent(msg2
, &width
, NULL
);
1945 if (width
> result
) result
= width
;
1946 const wxString
& msg3
= wmsg(/*Elevation*/118);
1947 GetTextExtent(msg3
, &width
, NULL
);
1948 if (width
> result
) result
= width
;
1953 int GfxCore::GetCompassXPosition() const
1955 // Return the x-coordinate of the centre of the compass in window
1957 return GetXSize() - INDICATOR_OFFSET_X
- GetCompassWidth() / 2;
1960 int GfxCore::GetClinoXPosition() const
1962 // Return the x-coordinate of the centre of the compass in window
1964 return GetXSize() - GetClinoOffset() - GetClinoWidth() / 2;
1967 int GfxCore::GetIndicatorYPosition() const
1969 // Return the y-coordinate of the centre of the indicators in window
1971 return GetYSize() - INDICATOR_OFFSET_Y
- INDICATOR_BOX_SIZE
/ 2;
1974 int GfxCore::GetIndicatorRadius() const
1976 // Return the radius of each indicator.
1977 return (INDICATOR_BOX_SIZE
- INDICATOR_MARGIN
* 2) / 2;
1980 bool GfxCore::PointWithinCompass(wxPoint point
) const
1982 // Determine whether a point (in window coordinates) lies within the
1984 if (!ShowingCompass()) return false;
1986 glaCoord dx
= point
.x
- GetCompassXPosition();
1987 glaCoord dy
= point
.y
- GetIndicatorYPosition();
1988 glaCoord radius
= GetIndicatorRadius();
1990 return (dx
* dx
+ dy
* dy
<= radius
* radius
);
1993 bool GfxCore::PointWithinClino(wxPoint point
) const
1995 // Determine whether a point (in window coordinates) lies within the clino.
1996 if (!ShowingClino()) return false;
1998 glaCoord dx
= point
.x
- GetClinoXPosition();
1999 glaCoord dy
= point
.y
- GetIndicatorYPosition();
2000 glaCoord radius
= GetIndicatorRadius();
2002 return (dx
* dx
+ dy
* dy
<= radius
* radius
);
2005 bool GfxCore::PointWithinScaleBar(wxPoint point
) const
2007 // Determine whether a point (in window coordinates) lies within the scale
2009 if (!ShowingScaleBar()) return false;
2011 return (point
.x
>= SCALE_BAR_OFFSET_X
&&
2012 point
.x
<= SCALE_BAR_OFFSET_X
+ m_ScaleBarWidth
&&
2013 point
.y
<= GetYSize() - SCALE_BAR_OFFSET_Y
- SCALE_BAR_HEIGHT
&&
2014 point
.y
>= GetYSize() - SCALE_BAR_OFFSET_Y
- SCALE_BAR_HEIGHT
*2);
2017 bool GfxCore::PointWithinColourKey(wxPoint point
) const
2019 // Determine whether a point (in window coordinates) lies within the key.
2020 point
.x
-= GetXSize() - KEY_OFFSET_X
;
2021 point
.y
= KEY_OFFSET_Y
- point
.y
;
2022 return (point
.x
>= key_lowerleft
[m_ColourBy
].x
&& point
.x
<= 0 &&
2023 point
.y
>= key_lowerleft
[m_ColourBy
].y
&& point
.y
<= 0);
2026 void GfxCore::SetCompassFromPoint(wxPoint point
)
2028 // Given a point in window coordinates, set the heading of the survey. If
2029 // the point is outside the compass, it snaps to 45 degree intervals;
2030 // otherwise it operates as normal.
2032 wxCoord dx
= point
.x
- GetCompassXPosition();
2033 wxCoord dy
= point
.y
- GetIndicatorYPosition();
2034 wxCoord radius
= GetIndicatorRadius();
2036 double angle
= deg(atan2(double(dx
), double(dy
))) - 180.0;
2037 if (dx
* dx
+ dy
* dy
<= radius
* radius
) {
2038 TurnCave(angle
- m_PanAngle
);
2039 m_MouseOutsideCompass
= false;
2041 TurnCave(int(angle
/ 45.0) * 45.0 - m_PanAngle
);
2042 m_MouseOutsideCompass
= true;
2048 void GfxCore::SetClinoFromPoint(wxPoint point
)
2050 // Given a point in window coordinates, set the elevation of the survey.
2051 // If the point is outside the clino, it snaps to 90 degree intervals;
2052 // otherwise it operates as normal.
2054 glaCoord dx
= point
.x
- GetClinoXPosition();
2055 glaCoord dy
= point
.y
- GetIndicatorYPosition();
2056 glaCoord radius
= GetIndicatorRadius();
2058 if (dx
>= 0 && dx
* dx
+ dy
* dy
<= radius
* radius
) {
2059 TiltCave(-deg(atan2(double(dy
), double(dx
))) - m_TiltAngle
);
2060 m_MouseOutsideElev
= false;
2061 } else if (dy
>= INDICATOR_MARGIN
) {
2062 TiltCave(-90.0 - m_TiltAngle
);
2063 m_MouseOutsideElev
= true;
2064 } else if (dy
<= -INDICATOR_MARGIN
) {
2065 TiltCave(90.0 - m_TiltAngle
);
2066 m_MouseOutsideElev
= true;
2068 TiltCave(-m_TiltAngle
);
2069 m_MouseOutsideElev
= true;
2075 void GfxCore::SetScaleBarFromOffset(wxCoord dx
)
2077 // Set the scale of the survey, given an offset as to how much the mouse has
2078 // been dragged over the scalebar since the last scale change.
2080 SetScale((m_ScaleBarWidth
+ dx
) * m_Scale
/ m_ScaleBarWidth
);
2084 void GfxCore::RedrawIndicators()
2086 // Redraw the compass and clino indicators.
2088 int total_width
= GetCompassWidth() + INDICATOR_GAP
+ GetClinoWidth();
2089 RefreshRect(wxRect(GetXSize() - INDICATOR_OFFSET_X
- total_width
,
2090 GetYSize() - INDICATOR_OFFSET_Y
- INDICATOR_BOX_SIZE
,
2092 INDICATOR_BOX_SIZE
), false);
2095 void GfxCore::StartRotation()
2097 // Start the survey rotating.
2099 if (m_SwitchingTo
>= NORTH
)
2105 void GfxCore::ToggleRotation()
2107 // Toggle the survey rotation on/off.
2116 void GfxCore::StopRotation()
2118 // Stop the survey rotating.
2124 bool GfxCore::IsExtendedElevation() const
2126 return m_Parent
->IsExtendedElevation();
2129 void GfxCore::ReverseRotation()
2131 // Reverse the direction of rotation.
2133 m_RotationStep
= -m_RotationStep
;
2138 void GfxCore::RotateSlower(bool accel
)
2140 // Decrease the speed of rotation, optionally by an increased amount.
2141 if (fabs(m_RotationStep
) == 1.0)
2144 m_RotationStep
*= accel
? (1 / 1.44) : (1 / 1.2);
2146 if (fabs(m_RotationStep
) < 1.0) {
2147 m_RotationStep
= (m_RotationStep
> 0 ? 1.0 : -1.0);
2153 void GfxCore::RotateFaster(bool accel
)
2155 // Increase the speed of rotation, optionally by an increased amount.
2156 if (fabs(m_RotationStep
) == 180.0)
2159 m_RotationStep
*= accel
? 1.44 : 1.2;
2160 if (fabs(m_RotationStep
) > 180.0) {
2161 m_RotationStep
= (m_RotationStep
> 0 ? 180.0 : -180.0);
2167 void GfxCore::SwitchToElevation()
2169 // Perform an animated switch to elevation view.
2171 if (m_SwitchingTo
!= ELEVATION
) {
2173 m_SwitchingTo
= ELEVATION
;
2175 // A second order to switch takes us there right away
2176 TiltCave(-m_TiltAngle
);
2182 void GfxCore::SwitchToPlan()
2184 // Perform an animated switch to plan view.
2186 if (m_SwitchingTo
!= PLAN
) {
2188 m_SwitchingTo
= PLAN
;
2190 // A second order to switch takes us there right away
2191 TiltCave(-90.0 - m_TiltAngle
);
2197 void GfxCore::SetViewTo(Double xmin
, Double xmax
, Double ymin
, Double ymax
, Double zmin
, Double zmax
)
2200 SetTranslation(-Vector3((xmin
+ xmax
) / 2, (ymin
+ ymax
) / 2, (zmin
+ zmax
) / 2));
2201 Double scale
= HUGE_VAL
;
2202 const Vector3 ext
= m_Parent
->GetExtent();
2204 Double s
= ext
.GetX() / (xmax
- xmin
);
2205 if (s
< scale
) scale
= s
;
2208 Double s
= ext
.GetY() / (ymax
- ymin
);
2209 if (s
< scale
) scale
= s
;
2211 if (!ShowingPlan() && zmax
> zmin
) {
2212 Double s
= ext
.GetZ() / (zmax
- zmin
);
2213 if (s
< scale
) scale
= s
;
2215 if (scale
!= HUGE_VAL
) SetScale(scale
);
2219 bool GfxCore::CanRaiseViewpoint() const
2221 // Determine if the survey can be viewed from a higher angle of elevation.
2223 return GetPerspective() ? (m_TiltAngle
< 90.0) : (m_TiltAngle
> -90.0);
2226 bool GfxCore::CanLowerViewpoint() const
2228 // Determine if the survey can be viewed from a lower angle of elevation.
2230 return GetPerspective() ? (m_TiltAngle
> -90.0) : (m_TiltAngle
< 90.0);
2233 bool GfxCore::HasDepth() const
2235 return m_Parent
->GetDepthExtent() == 0.0;
2238 bool GfxCore::HasErrorInformation() const
2240 return m_Parent
->HasErrorInformation();
2243 bool GfxCore::HasDateInformation() const
2245 return m_Parent
->GetDateMin() >= 0;
2248 bool GfxCore::ShowingPlan() const
2250 // Determine if the survey is in plan view.
2252 return (m_TiltAngle
== -90.0);
2255 bool GfxCore::ShowingElevation() const
2257 // Determine if the survey is in elevation view.
2259 return (m_TiltAngle
== 0.0);
2262 bool GfxCore::ShowingMeasuringLine() const
2264 // Determine if the measuring line is being shown. Only check if "there"
2265 // is valid, since that means the measuring line anchor is out.
2270 void GfxCore::ToggleFlag(bool* flag
, int update
)
2273 if (update
== UPDATE_BLOBS
) {
2275 } else if (update
== UPDATE_BLOBS_AND_CROSSES
) {
2277 InvalidateList(LIST_CROSSES
);
2278 m_HitTestGridValid
= false;
2283 int GfxCore::GetNumEntrances() const
2285 return m_Parent
->GetNumEntrances();
2288 int GfxCore::GetNumFixedPts() const
2290 return m_Parent
->GetNumFixedPts();
2293 int GfxCore::GetNumExportedPts() const
2295 return m_Parent
->GetNumExportedPts();
2298 void GfxCore::ToggleTerrain()
2300 ToggleFlag(&m_Terrain
);
2301 if (m_Terrain
&& !dem
) {
2302 wxCommandEvent dummy
;
2303 m_Parent
->OnOpenTerrain(dummy
);
2307 void GfxCore::ToggleFatFinger()
2309 if (sqrd_measure_threshold
== sqrd(MEASURE_THRESHOLD
)) {
2310 sqrd_measure_threshold
= sqrd(5 * MEASURE_THRESHOLD
);
2311 wxMessageBox(wxT("Fat finger enabled"), wxT("Aven Debug"), wxOK
| wxICON_INFORMATION
);
2313 sqrd_measure_threshold
= sqrd(MEASURE_THRESHOLD
);
2314 wxMessageBox(wxT("Fat finger disabled"), wxT("Aven Debug"), wxOK
| wxICON_INFORMATION
);
2318 void GfxCore::ClearTreeSelection()
2320 m_Parent
->ClearTreeSelection();
2323 void GfxCore::CentreOn(const Point
&p
)
2326 m_HitTestGridValid
= false;
2331 void GfxCore::ForceRefresh()
2336 void GfxCore::GenerateList(unsigned int l
)
2347 case LIST_CLINO_BACK
:
2350 case LIST_SCALE_BAR
:
2353 case LIST_DEPTH_KEY
:
2359 case LIST_ERROR_KEY
:
2362 case LIST_GRADIENT_KEY
:
2365 case LIST_LENGTH_KEY
:
2368 case LIST_UNDERGROUND_LEGS
:
2369 GenerateDisplayList(false);
2372 GenerateDisplayListTubes();
2374 case LIST_SURFACE_LEGS
:
2375 GenerateDisplayList(true);
2378 GenerateBlobsDisplayList();
2380 case LIST_CROSSES
: {
2382 SetColour(col_LIGHT_GREY
);
2383 list
<LabelInfo
*>::const_iterator pos
= m_Parent
->GetLabels();
2384 while (pos
!= m_Parent
->GetLabelsEnd()) {
2385 const LabelInfo
* label
= *pos
++;
2387 if ((m_Surface
&& label
->IsSurface()) ||
2388 (m_Legs
&& label
->IsUnderground()) ||
2389 (!label
->IsSurface() && !label
->IsUnderground())) {
2390 // Check if this station should be displayed
2391 // (last case is for stns with no legs attached)
2392 DrawCross(label
->GetX(), label
->GetY(), label
->GetZ());
2402 GenerateDisplayListShadow();
2413 void GfxCore::ToggleSmoothShading()
2415 GLACanvas::ToggleSmoothShading();
2416 InvalidateList(LIST_TUBES
);
2420 void GfxCore::GenerateDisplayList(bool surface
)
2422 unsigned surf_or_not
= surface
? img_FLAG_SURFACE
: 0;
2423 // Generate the display list for the surface or underground legs.
2424 for (int f
= 0; f
!= 8; ++f
) {
2425 if ((f
& img_FLAG_SURFACE
) != surf_or_not
) continue;
2426 const unsigned SHOW_DASHED_AND_FADED
= unsigned(-1);
2427 unsigned style
= SHOW_NORMAL
;
2428 if ((f
& img_FLAG_SPLAY
) && m_Splays
!= SHOW_NORMAL
) {
2430 } else if (f
& img_FLAG_DUPLICATE
) {
2433 if (f
& img_FLAG_SURFACE
) {
2434 if (style
== SHOW_FADED
) {
2435 style
= SHOW_DASHED_AND_FADED
;
2437 style
= SHOW_DASHED
;
2448 EnableDashedLines();
2450 case SHOW_DASHED_AND_FADED
:
2452 EnableDashedLines();
2456 void (GfxCore::* add_poly
)(const traverse
&);
2458 if (m_ColourBy
== COLOUR_BY_ERROR
) {
2459 add_poly
= &GfxCore::AddPolylineError
;
2461 add_poly
= &GfxCore::AddPolyline
;
2467 list
<traverse
>::const_iterator trav
= m_Parent
->traverses_begin(f
);
2468 list
<traverse
>::const_iterator tend
= m_Parent
->traverses_end(f
);
2469 while (trav
!= tend
) {
2470 (this->*add_poly
)(*trav
);
2479 DisableDashedLines();
2481 case SHOW_DASHED_AND_FADED
:
2482 DisableDashedLines();
2489 void GfxCore::GenerateDisplayListTubes()
2491 // Generate the display list for the tubes.
2492 list
<vector
<XSect
> >::iterator trav
= m_Parent
->tubes_begin();
2493 list
<vector
<XSect
> >::iterator tend
= m_Parent
->tubes_end();
2494 while (trav
!= tend
) {
2500 void GfxCore::GenerateDisplayListShadow()
2502 SetColour(col_BLACK
);
2503 for (int f
= 0; f
!= 8; ++f
) {
2504 // Only include underground legs in the shadow.
2505 if ((f
& img_FLAG_SURFACE
) != 0) continue;
2506 list
<traverse
>::const_iterator trav
= m_Parent
->traverses_begin(f
);
2507 list
<traverse
>::const_iterator tend
= m_Parent
->traverses_end(f
);
2508 while (trav
!= tend
) {
2509 AddPolylineShadow(*trav
);
2516 GfxCore::parse_hgt_filename(const wxString
& lc_name
)
2518 char * leaf
= leaf_from_fnm(lc_name
.utf8_str());
2519 const char * p
= leaf
;
2522 o_y
= strtoul(p
, &q
, 10);
2528 o_x
= strtoul(p
, &q
, 10);
2532 nodata_value
= -32768;
2537 GfxCore::parse_hdr(wxInputStream
& is
, unsigned long & skipbytes
)
2539 // ESRI docs say NBITS defaults to 8.
2540 unsigned long nbits
= 8;
2541 // ESRI docs say NBANDS defaults to 1.
2542 unsigned long nbands
= 1;
2543 unsigned long bandrowbytes
= 0;
2544 unsigned long totalrowbytes
= 0;
2545 // ESRI docs say ULXMAP defaults to 0.
2547 // ESRI docs say ULYMAP defaults to NROWS - 1.
2549 // ESRI docs say XDIM and YDIM default to 1.
2550 step_x
= step_y
= 1.0;
2554 while ((ch
= is
.GetC()) != wxEOF
) {
2555 if (ch
== '\n' || ch
== '\r') break;
2558 #define CHECK(X, COND) \
2559 } else if (line.StartsWith(wxT(X " "))) { \
2560 size_t v = line.find_first_not_of(wxT(' '), sizeof(X)); \
2561 if (v == line.npos || !(COND)) { \
2562 err += wxT("Unexpected value for " X); \
2566 // I = little-endian; M = big-endian
2567 CHECK("BYTEORDER", (bigendian
= (line
[v
] == 'M')) || line
[v
] == 'I')
2568 // ESRI docs say LAYOUT defaults to BIL if not specified.
2569 CHECK("LAYOUT", line
.substr(v
) == wxT("BIL"))
2570 CHECK("NROWS", line
.substr(v
).ToCULong(&dem_height
))
2571 CHECK("NCOLS", line
.substr(v
).ToCULong(&dem_width
))
2572 // ESRI docs say NBANDS defaults to 1 if not specified.
2573 CHECK("NBANDS", line
.substr(v
).ToCULong(&nbands
) && nbands
== 1)
2574 CHECK("NBITS", line
.substr(v
).ToCULong(&nbits
) && nbits
== 16)
2575 CHECK("BANDROWBYTES", line
.substr(v
).ToCULong(&bandrowbytes
))
2576 CHECK("TOTALROWBYTES", line
.substr(v
).ToCULong(&totalrowbytes
))
2577 // PIXELTYPE is a GDAL extension, so may not be present.
2578 CHECK("PIXELTYPE", line
.substr(v
) == wxT("SIGNEDINT"))
2579 CHECK("ULXMAP", line
.substr(v
).ToCDouble(&o_x
))
2580 CHECK("ULYMAP", line
.substr(v
).ToCDouble(&o_y
))
2581 CHECK("XDIM", line
.substr(v
).ToCDouble(&step_x
))
2582 CHECK("YDIM", line
.substr(v
).ToCDouble(&step_y
))
2583 CHECK("NODATA", line
.substr(v
).ToCLong(&nodata_value
))
2584 CHECK("SKIPBYTES", line
.substr(v
).ToCULong(&skipbytes
))
2590 if (o_y
== HUGE_VAL
) {
2591 o_y
= dem_height
- 1;
2593 if (bandrowbytes
!= 0) {
2594 if (nbits
* dem_width
!= bandrowbytes
* 8) {
2595 wxMessageBox("BANDROWBYTES setting indicates unused bits after each band - not currently supported");
2598 if (totalrowbytes
!= 0) {
2599 // This is the ESRI default for BIL, for BIP it would be
2600 // nbands * bandrowbytes.
2601 if (nbands
* nbits
* dem_width
!= totalrowbytes
* 8) {
2602 wxMessageBox("TOTALROWBYTES setting indicates unused bits after "
2603 "each row - not currently supported");
2606 return ((nbits
* dem_width
+ 7) / 8) * dem_height
;
2610 GfxCore::read_bil(wxInputStream
& is
, size_t size
, unsigned long skipbytes
)
2612 bool know_size
= true;
2614 // If the stream doesn't know its size, GetSize() returns 0.
2615 size
= is
.GetSize();
2617 size
= DEFAULT_HGT_SIZE
;
2621 dem
= new unsigned short[size
/ 2];
2623 if (is
.SeekI(skipbytes
, wxFromStart
) == ::wxInvalidOffset
) {
2625 unsigned long to_read
= skipbytes
;
2626 if (size
< to_read
) to_read
= size
;
2627 is
.Read(reinterpret_cast<char *>(dem
), to_read
);
2628 size_t c
= is
.LastRead();
2630 wxMessageBox(wxT("Failed to skip terrain data header"));
2638 #if wxCHECK_VERSION(2,9,5)
2639 if (!is
.ReadAll(dem
, size
)) {
2641 // FIXME: On __WXMSW__ currently we fail to
2642 // read any data from files in zips.
2645 wxMessageBox(wxT("Failed to read terrain data"));
2648 size
= is
.LastRead();
2651 char * p
= reinterpret_cast<char *>(dem
);
2654 size_t c
= is
.LastRead();
2657 size
= DEFAULT_HGT_SIZE
- size
;
2663 wxMessageBox(wxT("Failed to read terrain data"));
2671 if (dem_width
== 0 && dem_height
== 0) {
2672 dem_width
= dem_height
= sqrt(size
/ 2);
2673 if (dem_width
* dem_height
* 2 != size
) {
2676 wxMessageBox(wxT("HGT format data doesn't form a square"));
2679 step_x
= step_y
= 1.0 / dem_width
;
2685 bool GfxCore::LoadDEM(const wxString
& file
)
2687 if (m_Parent
->m_cs_proj
.empty()) {
2688 wxMessageBox(wxT("No coordinate system specified in survey data"));
2696 // Default is to not skip any bytes.
2697 unsigned long skipbytes
= 0;
2698 // For .hgt files, default to using filesize to determine.
2699 dem_width
= dem_height
= 0;
2700 // ESRI say "The default byte order is the same as that of the host machine
2701 // executing the software", but that's stupid so we default to
2705 wxFileInputStream
fs(file
);
2707 wxMessageBox(wxT("Failed to open DEM file"));
2711 const wxString
& lc_file
= file
.Lower();
2712 if (lc_file
.EndsWith(wxT(".hgt"))) {
2713 parse_hgt_filename(lc_file
);
2714 read_bil(fs
, size
, skipbytes
);
2715 } else if (lc_file
.EndsWith(wxT(".bil"))) {
2716 wxString hdr_file
= file
;
2717 hdr_file
.replace(file
.size() - 4, 4, wxT(".hdr"));
2718 wxFileInputStream
hdr_is(hdr_file
);
2719 if (!hdr_is
.IsOk()) {
2720 wxMessageBox(wxT("Failed to open HDR file '") + hdr_file
+ wxT("'"));
2723 size
= parse_hdr(hdr_is
, skipbytes
);
2724 read_bil(fs
, size
, skipbytes
);
2725 } else if (lc_file
.EndsWith(wxT(".zip"))) {
2726 wxZipEntry
* ze_data
= NULL
;
2727 wxZipInputStream
zs(fs
);
2729 while ((ze
= zs
.GetNextEntry()) != NULL
) {
2731 const wxString
& lc_name
= ze
->GetName().Lower();
2732 if (!ze_data
&& lc_name
.EndsWith(wxT(".hgt"))) {
2733 // SRTM .hgt files are raw binary data, with the filename
2734 // encoding the coordinates.
2735 parse_hgt_filename(lc_name
);
2736 read_bil(zs
, size
, skipbytes
);
2741 if (!ze_data
&& lc_name
.EndsWith(wxT(".bil"))) {
2743 read_bil(zs
, size
, skipbytes
);
2750 if (lc_name
.EndsWith(wxT(".hdr"))) {
2751 size
= parse_hdr(zs
, skipbytes
);
2753 if (!zs
.OpenEntry(*ze_data
)) {
2754 wxMessageBox(wxT("Couldn't read DEM data from .zip file"));
2757 read_bil(zs
, size
, skipbytes
);
2759 } else if (lc_name
.EndsWith(wxT(".prj"))) {
2760 //FIXME: check this matches the datum string we use
2761 //Projection GEOGRAPHIC
2766 //Xshift 0.0000000000
2767 //Yshift 0.0000000000
2780 InvalidateList(LIST_TERRAIN
);
2785 void GfxCore::DrawTerrainTriangle(const Vector3
& a
, const Vector3
& b
, const Vector3
& c
)
2787 Vector3 n
= (b
- a
) * (c
- a
);
2789 Double factor
= dot(n
, light
) * .95 + .05;
2790 SetColour(col_WHITE
, factor
);
2797 // Like wxBusyCursor, but you can cancel it early.
2798 class AvenBusyCursor
{
2802 AvenBusyCursor() : active(true) {
2803 wxBeginBusyCursor();
2818 void GfxCore::DrawTerrain()
2822 AvenBusyCursor hourglass
;
2824 // Draw terrain to twice the extent, or at least 1km.
2825 double r_sqrd
= sqrd(max(m_Parent
->GetExtent().magnitude(), 1000.0));
2826 #define WGS84_DATUM_STRING "+proj=longlat +ellps=WGS84 +datum=WGS84"
2827 static projPJ pj_in
= pj_init_plus(WGS84_DATUM_STRING
);
2833 error(/*Failed to initialise input coordinate system “%s”*/287, WGS84_DATUM_STRING
);
2836 static projPJ pj_out
= pj_init_plus(m_Parent
->m_cs_proj
.c_str());
2842 error(/*Failed to initialise output coordinate system “%s”*/288, (const char *)m_Parent
->m_cs_proj
.c_str());
2848 const Vector3
& off
= m_Parent
->GetOffset();
2849 vector
<Vector3
> prevcol(dem_height
+ 1);
2850 for (size_t x
= 0; x
< dem_width
; ++x
) {
2851 double X_
= (o_x
+ x
* step_x
) * DEG_TO_RAD
;
2853 for (size_t y
= 0; y
< dem_height
; ++y
) {
2854 unsigned short elev
= dem
[x
+ y
* dem_width
];
2855 #ifdef WORDS_BIGENDIAN
2856 const bool MACHINE_BIGENDIAN
= true;
2858 const bool MACHINE_BIGENDIAN
= false;
2860 if (bigendian
!= MACHINE_BIGENDIAN
) {
2861 #if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__ >= 408)
2862 elev
= __builtin_bswap16(elev
);
2864 elev
= (elev
>> 8) | (elev
<< 8);
2867 double Z
= (short)elev
;
2869 if (Z
== nodata_value
) {
2870 pt
= Vector3(DBL_MAX
, DBL_MAX
, DBL_MAX
);
2873 double Y
= (o_y
- y
* step_y
) * DEG_TO_RAD
;
2874 pj_transform(pj_in
, pj_out
, 1, 1, &X
, &Y
, &Z
);
2875 pt
= Vector3(X
, Y
, Z
) - off
;
2876 double dist_2
= sqrd(pt
.GetX()) + sqrd(pt
.GetY());
2877 if (dist_2
> r_sqrd
) {
2878 pt
= Vector3(DBL_MAX
, DBL_MAX
, DBL_MAX
);
2881 if (x
> 0 && y
> 0) {
2882 const Vector3
& a
= prevcol
[y
- 1];
2883 const Vector3
& b
= prevcol
[y
];
2884 // If all points are valid, split the quadrilateral into
2885 // triangles along the shorter 3D diagonal, which typically
2889 // prev---a x prev---a
2891 // y | | / | or | \ |
2897 enum { NONE
= 0, P
= 1, Q
= 2, R
= 4, S
= 8, ALL
= P
|Q
|R
|S
};
2899 ((prev
.GetZ() != DBL_MAX
)) |
2900 ((a
.GetZ() != DBL_MAX
) << 1) |
2901 ((b
.GetZ() != DBL_MAX
) << 2) |
2902 ((pt
.GetZ() != DBL_MAX
) << 3);
2903 static const int tris_map
[16] = {
2904 NONE
, // nothing valid
2919 ALL
, // pt, b, a, prev
2921 int tris
= tris_map
[valid
];
2923 // All points valid.
2924 if ((a
- b
).magnitude() < (prev
- pt
).magnitude()) {
2931 DrawTerrainTriangle(a
, prev
, b
);
2933 DrawTerrainTriangle(a
, b
, pt
);
2935 DrawTerrainTriangle(pt
, prev
, b
);
2937 DrawTerrainTriangle(a
, prev
, pt
);
2940 prevcol
[y
].assign(pt
);
2950 /* TRANSLATORS: Aven shows a circle of terrain covering the area
2951 * of the survey plus a bit, but the terrain data file didn't
2952 * contain any data inside that circle.
2954 error(/*No terrain data near area of survey*/161);
2959 void GfxCore::GenerateBlobsDisplayList()
2961 if (!(m_Entrances
|| m_FixedPts
|| m_ExportedPts
||
2962 m_Parent
->GetNumHighlightedPts()))
2966 gla_colour prev_col
= col_BLACK
; // not a colour used for blobs
2967 list
<LabelInfo
*>::const_iterator pos
= m_Parent
->GetLabels();
2969 while (pos
!= m_Parent
->GetLabelsEnd()) {
2970 const LabelInfo
* label
= *pos
++;
2972 // When more than one flag is set on a point:
2973 // search results take priority over entrance highlighting
2974 // which takes priority over fixed point
2975 // highlighting, which in turn takes priority over exported
2976 // point highlighting.
2978 if (!((m_Surface
&& label
->IsSurface()) ||
2979 (m_Legs
&& label
->IsUnderground()) ||
2980 (!label
->IsSurface() && !label
->IsUnderground()))) {
2981 // if this station isn't to be displayed, skip to the next
2982 // (last case is for stns with no legs attached)
2988 if (label
->IsHighLighted()) {
2990 } else if (m_Entrances
&& label
->IsEntrance()) {
2992 } else if (m_FixedPts
&& label
->IsFixedPt()) {
2994 } else if (m_ExportedPts
&& label
->IsExportedPt()) {
2995 col
= col_TURQUOISE
;
3000 // Stations are sorted by blob type, so colour changes are infrequent.
3001 if (col
!= prev_col
) {
3005 DrawBlob(label
->GetX(), label
->GetY(), label
->GetZ());
3010 void GfxCore::DrawIndicators()
3014 drawing_list key_list
= LIST_LIMIT_
;
3015 switch (m_ColourBy
) {
3016 case COLOUR_BY_DEPTH
:
3017 key_list
= LIST_DEPTH_KEY
; break;
3018 case COLOUR_BY_DATE
:
3019 key_list
= LIST_DATE_KEY
; break;
3020 case COLOUR_BY_ERROR
:
3021 key_list
= LIST_ERROR_KEY
; break;
3022 case COLOUR_BY_GRADIENT
:
3023 key_list
= LIST_GRADIENT_KEY
; break;
3024 case COLOUR_BY_LENGTH
:
3025 key_list
= LIST_LENGTH_KEY
; break;
3027 if (key_list
!= LIST_LIMIT_
) {
3028 DrawList2D(key_list
, GetXSize() - KEY_OFFSET_X
,
3029 GetYSize() - KEY_OFFSET_Y
, 0);
3033 // Draw compass or elevation/heading indicators.
3034 if (m_Compass
|| m_Clino
) {
3035 if (!m_Parent
->IsExtendedElevation()) Draw2dIndicators();
3040 DrawList2D(LIST_SCALE_BAR
, 0, 0, 0);
3044 void GfxCore::PlaceVertexWithColour(const Vector3
& v
,
3045 glaTexCoord tex_x
, glaTexCoord tex_y
,
3048 SetColour(col_WHITE
, factor
);
3049 PlaceVertex(v
, tex_x
, tex_y
);
3052 void GfxCore::SetDepthColour(Double z
, Double factor
) {
3053 // Set the drawing colour based on the altitude.
3054 Double z_ext
= m_Parent
->GetDepthExtent();
3056 z
-= m_Parent
->GetDepthMin();
3057 // points arising from tubes may be slightly outside the limits...
3059 if (z
> z_ext
) z
= z_ext
;
3062 SetColour(GetPen(0), factor
);
3066 assert(z_ext
> 0.0);
3067 Double how_far
= z
/ z_ext
;
3068 assert(how_far
>= 0.0);
3069 assert(how_far
<= 1.0);
3071 int band
= int(floor(how_far
* (GetNumColourBands() - 1)));
3072 GLAPen pen1
= GetPen(band
);
3073 if (band
< GetNumColourBands() - 1) {
3074 const GLAPen
& pen2
= GetPen(band
+ 1);
3076 Double interval
= z_ext
/ (GetNumColourBands() - 1);
3077 Double into_band
= z
/ interval
- band
;
3079 // printf("%g z_offset=%g interval=%g band=%d\n", into_band,
3080 // z_offset, interval, band);
3081 // FIXME: why do we need to clamp here? Is it because the walls can
3082 // extend further up/down than the centre-line?
3083 if (into_band
< 0.0) into_band
= 0.0;
3084 if (into_band
> 1.0) into_band
= 1.0;
3085 assert(into_band
>= 0.0);
3086 assert(into_band
<= 1.0);
3088 pen1
.Interpolate(pen2
, into_band
);
3090 SetColour(pen1
, factor
);
3093 void GfxCore::PlaceVertexWithDepthColour(const Vector3
&v
, Double factor
)
3095 SetDepthColour(v
.GetZ(), factor
);
3099 void GfxCore::PlaceVertexWithDepthColour(const Vector3
&v
,
3100 glaTexCoord tex_x
, glaTexCoord tex_y
,
3103 SetDepthColour(v
.GetZ(), factor
);
3104 PlaceVertex(v
, tex_x
, tex_y
);
3107 void GfxCore::SplitLineAcrossBands(int band
, int band2
,
3108 const Vector3
&p
, const Vector3
&q
,
3111 const int step
= (band
< band2
) ? 1 : -1;
3112 for (int i
= band
; i
!= band2
; i
+= step
) {
3113 const Double z
= GetDepthBoundaryBetweenBands(i
, i
+ step
);
3115 // Find the intersection point of the line p -> q
3116 // with the plane parallel to the xy-plane with z-axis intersection z.
3117 assert(q
.GetZ() - p
.GetZ() != 0.0);
3119 const Double t
= (z
- p
.GetZ()) / (q
.GetZ() - p
.GetZ());
3120 // assert(0.0 <= t && t <= 1.0); FIXME: rounding problems!
3122 const Double x
= p
.GetX() + t
* (q
.GetX() - p
.GetX());
3123 const Double y
= p
.GetY() + t
* (q
.GetY() - p
.GetY());
3125 PlaceVertexWithDepthColour(Vector3(x
, y
, z
), factor
);
3129 void GfxCore::SplitPolyAcrossBands(vector
<vector
<Split
> >& splits
,
3130 int band
, int band2
,
3131 const Vector3
&p
, const Vector3
&q
,
3132 glaTexCoord ptx
, glaTexCoord pty
,
3133 glaTexCoord w
, glaTexCoord h
)
3135 const int step
= (band
< band2
) ? 1 : -1;
3136 for (int i
= band
; i
!= band2
; i
+= step
) {
3137 const Double z
= GetDepthBoundaryBetweenBands(i
, i
+ step
);
3139 // Find the intersection point of the line p -> q
3140 // with the plane parallel to the xy-plane with z-axis intersection z.
3141 assert(q
.GetZ() - p
.GetZ() != 0.0);
3143 const Double t
= (z
- p
.GetZ()) / (q
.GetZ() - p
.GetZ());
3144 // assert(0.0 <= t && t <= 1.0); FIXME: rounding problems!
3146 const Double x
= p
.GetX() + t
* (q
.GetX() - p
.GetX());
3147 const Double y
= p
.GetY() + t
* (q
.GetY() - p
.GetY());
3148 glaTexCoord tx
= ptx
, ty
= pty
;
3152 splits
[i
].push_back(Split(Vector3(x
, y
, z
), tx
, ty
));
3153 splits
[i
+ step
].push_back(Split(Vector3(x
, y
, z
), tx
, ty
));
3157 int GfxCore::GetDepthColour(Double z
) const
3159 // Return the (0-based) depth colour band index for a z-coordinate.
3160 Double z_ext
= m_Parent
->GetDepthExtent();
3161 z
-= m_Parent
->GetDepthMin();
3162 // We seem to get rounding differences causing z to sometimes be slightly
3163 // less than GetDepthMin() here, and it can certainly be true for passage
3164 // tubes, so just clamp the value to 0.
3165 if (z
<= 0) return 0;
3166 // We seem to get rounding differences causing z to sometimes exceed z_ext
3167 // by a small amount here (see: https://trac.survex.com/ticket/26) and it
3168 // can certainly be true for passage tubes, so just clamp the value.
3169 if (z
>= z_ext
) return GetNumColourBands() - 1;
3170 return int(z
/ z_ext
* (GetNumColourBands() - 1));
3173 Double
GfxCore::GetDepthBoundaryBetweenBands(int a
, int b
) const
3175 // Return the z-coordinate of the depth colour boundary between
3176 // two adjacent depth colour bands (specified by 0-based indices).
3178 assert((a
== b
- 1) || (a
== b
+ 1));
3179 if (GetNumColourBands() == 1) return 0;
3181 int band
= (a
> b
) ? a
: b
; // boundary N lies on the bottom of band N.
3182 Double z_ext
= m_Parent
->GetDepthExtent();
3183 return (z_ext
* band
/ (GetNumColourBands() - 1)) + m_Parent
->GetDepthMin();
3186 void GfxCore::AddPolyline(const traverse
& centreline
)
3189 SetColour(col_WHITE
);
3190 vector
<PointInfo
>::const_iterator i
= centreline
.begin();
3193 while (i
!= centreline
.end()) {
3200 void GfxCore::AddPolylineShadow(const traverse
& centreline
)
3203 const double z
= -0.5 * m_Parent
->GetZExtent();
3204 vector
<PointInfo
>::const_iterator i
= centreline
.begin();
3205 PlaceVertex(i
->GetX(), i
->GetY(), z
);
3207 while (i
!= centreline
.end()) {
3208 PlaceVertex(i
->GetX(), i
->GetY(), z
);
3214 void GfxCore::AddPolylineDepth(const traverse
& centreline
)
3217 vector
<PointInfo
>::const_iterator i
, prev_i
;
3218 i
= centreline
.begin();
3219 int band0
= GetDepthColour(i
->GetZ());
3220 PlaceVertexWithDepthColour(*i
);
3223 while (i
!= centreline
.end()) {
3224 int band
= GetDepthColour(i
->GetZ());
3225 if (band
!= band0
) {
3226 SplitLineAcrossBands(band0
, band
, *prev_i
, *i
);
3229 PlaceVertexWithDepthColour(*i
);
3236 void GfxCore::AddQuadrilateral(const Vector3
&a
, const Vector3
&b
,
3237 const Vector3
&c
, const Vector3
&d
)
3239 Vector3 normal
= (a
- c
) * (d
- b
);
3241 Double factor
= dot(normal
, light
) * .3 + .7;
3242 glaTexCoord
w(((b
- a
).magnitude() + (d
- c
).magnitude()) * .5);
3243 glaTexCoord
h(((b
- c
).magnitude() + (d
- a
).magnitude()) * .5);
3244 // FIXME: should plot triangles instead to avoid rendering glitches.
3245 BeginQuadrilaterals();
3246 PlaceVertexWithColour(a
, 0, 0, factor
);
3247 PlaceVertexWithColour(b
, w
, 0, factor
);
3248 PlaceVertexWithColour(c
, w
, h
, factor
);
3249 PlaceVertexWithColour(d
, 0, h
, factor
);
3250 EndQuadrilaterals();
3253 void GfxCore::AddQuadrilateralDepth(const Vector3
&a
, const Vector3
&b
,
3254 const Vector3
&c
, const Vector3
&d
)
3256 Vector3 normal
= (a
- c
) * (d
- b
);
3258 Double factor
= dot(normal
, light
) * .3 + .7;
3259 int a_band
, b_band
, c_band
, d_band
;
3260 a_band
= GetDepthColour(a
.GetZ());
3261 a_band
= min(max(a_band
, 0), GetNumColourBands());
3262 b_band
= GetDepthColour(b
.GetZ());
3263 b_band
= min(max(b_band
, 0), GetNumColourBands());
3264 c_band
= GetDepthColour(c
.GetZ());
3265 c_band
= min(max(c_band
, 0), GetNumColourBands());
3266 d_band
= GetDepthColour(d
.GetZ());
3267 d_band
= min(max(d_band
, 0), GetNumColourBands());
3268 glaTexCoord
w(((b
- a
).magnitude() + (d
- c
).magnitude()) * .5);
3269 glaTexCoord
h(((b
- c
).magnitude() + (d
- a
).magnitude()) * .5);
3270 int min_band
= min(min(a_band
, b_band
), min(c_band
, d_band
));
3271 int max_band
= max(max(a_band
, b_band
), max(c_band
, d_band
));
3272 if (min_band
== max_band
) {
3273 // Simple case - the polygon is entirely within one band.
3275 //// PlaceNormal(normal);
3276 PlaceVertexWithDepthColour(a
, 0, 0, factor
);
3277 PlaceVertexWithDepthColour(b
, w
, 0, factor
);
3278 PlaceVertexWithDepthColour(c
, w
, h
, factor
);
3279 PlaceVertexWithDepthColour(d
, 0, h
, factor
);
3282 // We need to make a separate polygon for each depth band...
3283 vector
<vector
<Split
> > splits
;
3284 splits
.resize(max_band
+ 1);
3285 splits
[a_band
].push_back(Split(a
, 0, 0));
3286 if (a_band
!= b_band
) {
3287 SplitPolyAcrossBands(splits
, a_band
, b_band
, a
, b
, 0, 0, w
, 0);
3289 splits
[b_band
].push_back(Split(b
, w
, 0));
3290 if (b_band
!= c_band
) {
3291 SplitPolyAcrossBands(splits
, b_band
, c_band
, b
, c
, w
, 0, 0, h
);
3293 splits
[c_band
].push_back(Split(c
, w
, h
));
3294 if (c_band
!= d_band
) {
3295 SplitPolyAcrossBands(splits
, c_band
, d_band
, c
, d
, w
, h
, -w
, 0);
3297 splits
[d_band
].push_back(Split(d
, 0, h
));
3298 if (d_band
!= a_band
) {
3299 SplitPolyAcrossBands(splits
, d_band
, a_band
, d
, a
, 0, h
, 0, -h
);
3301 for (int band
= min_band
; band
<= max_band
; ++band
) {
3303 for (auto&& item
: splits
[band
]) {
3304 PlaceVertexWithDepthColour(item
.vec
, item
.tx
, item
.ty
, factor
);
3311 void GfxCore::SetColourFromDate(int date
, Double factor
)
3313 // Set the drawing colour based on a date.
3317 SetColour(col_WHITE
, factor
);
3321 int date_offset
= date
- m_Parent
->GetDateMin();
3322 if (date_offset
== 0) {
3323 // Earliest date - handle as a special case for the single date case.
3324 SetColour(GetPen(0), factor
);
3328 int date_ext
= m_Parent
->GetDateExtent();
3329 Double how_far
= (Double
)date_offset
/ date_ext
;
3330 assert(how_far
>= 0.0);
3331 assert(how_far
<= 1.0);
3332 SetColourFrom01(how_far
, factor
);
3335 void GfxCore::AddPolylineDate(const traverse
& centreline
)
3338 vector
<PointInfo
>::const_iterator i
, prev_i
;
3339 i
= centreline
.begin();
3340 int date
= i
->GetDate();
3341 SetColourFromDate(date
, 1.0);
3344 while (++i
!= centreline
.end()) {
3345 int newdate
= i
->GetDate();
3346 if (newdate
!= date
) {
3350 SetColourFromDate(date
, 1.0);
3351 PlaceVertex(*prev_i
);
3359 static int static_date_hack
; // FIXME
3361 void GfxCore::AddQuadrilateralDate(const Vector3
&a
, const Vector3
&b
,
3362 const Vector3
&c
, const Vector3
&d
)
3364 Vector3 normal
= (a
- c
) * (d
- b
);
3366 Double factor
= dot(normal
, light
) * .3 + .7;
3367 glaTexCoord
w(((b
- a
).magnitude() + (d
- c
).magnitude()) * .5);
3368 glaTexCoord
h(((b
- c
).magnitude() + (d
- a
).magnitude()) * .5);
3369 // FIXME: should plot triangles instead to avoid rendering glitches.
3370 BeginQuadrilaterals();
3371 //// PlaceNormal(normal);
3372 SetColourFromDate(static_date_hack
, factor
);
3373 PlaceVertex(a
, 0, 0);
3374 PlaceVertex(b
, w
, 0);
3375 PlaceVertex(c
, w
, h
);
3376 PlaceVertex(d
, 0, h
);
3377 EndQuadrilaterals();
3380 static double static_E_hack
; // FIXME
3382 void GfxCore::SetColourFromError(double E
, Double factor
)
3384 // Set the drawing colour based on an error value.
3387 SetColour(col_WHITE
, factor
);
3391 Double how_far
= E
/ MAX_ERROR
;
3392 assert(how_far
>= 0.0);
3393 if (how_far
> 1.0) how_far
= 1.0;
3394 SetColourFrom01(how_far
, factor
);
3397 void GfxCore::AddQuadrilateralError(const Vector3
&a
, const Vector3
&b
,
3398 const Vector3
&c
, const Vector3
&d
)
3400 Vector3 normal
= (a
- c
) * (d
- b
);
3402 Double factor
= dot(normal
, light
) * .3 + .7;
3403 glaTexCoord
w(((b
- a
).magnitude() + (d
- c
).magnitude()) * .5);
3404 glaTexCoord
h(((b
- c
).magnitude() + (d
- a
).magnitude()) * .5);
3405 // FIXME: should plot triangles instead to avoid rendering glitches.
3406 BeginQuadrilaterals();
3407 //// PlaceNormal(normal);
3408 SetColourFromError(static_E_hack
, factor
);
3409 PlaceVertex(a
, 0, 0);
3410 PlaceVertex(b
, w
, 0);
3411 PlaceVertex(c
, w
, h
);
3412 PlaceVertex(d
, 0, h
);
3413 EndQuadrilaterals();
3416 void GfxCore::AddPolylineError(const traverse
& centreline
)
3419 SetColourFromError(centreline
.E
, 1.0);
3420 vector
<PointInfo
>::const_iterator i
;
3421 for(i
= centreline
.begin(); i
!= centreline
.end(); ++i
) {
3427 // gradient is in *radians*.
3428 void GfxCore::SetColourFromGradient(double gradient
, Double factor
)
3430 // Set the drawing colour based on the gradient of the leg.
3432 const Double GRADIENT_MAX
= M_PI_2
;
3433 gradient
= fabs(gradient
);
3434 Double how_far
= gradient
/ GRADIENT_MAX
;
3435 SetColourFrom01(how_far
, factor
);
3438 void GfxCore::AddPolylineGradient(const traverse
& centreline
)
3440 vector
<PointInfo
>::const_iterator i
, prev_i
;
3441 i
= centreline
.begin();
3443 while (++i
!= centreline
.end()) {
3445 SetColourFromGradient((*i
- *prev_i
).gradient(), 1.0);
3446 PlaceVertex(*prev_i
);
3453 static double static_gradient_hack
; // FIXME
3455 void GfxCore::AddQuadrilateralGradient(const Vector3
&a
, const Vector3
&b
,
3456 const Vector3
&c
, const Vector3
&d
)
3458 Vector3 normal
= (a
- c
) * (d
- b
);
3460 Double factor
= dot(normal
, light
) * .3 + .7;
3461 glaTexCoord
w(((b
- a
).magnitude() + (d
- c
).magnitude()) * .5);
3462 glaTexCoord
h(((b
- c
).magnitude() + (d
- a
).magnitude()) * .5);
3463 // FIXME: should plot triangles instead to avoid rendering glitches.
3464 BeginQuadrilaterals();
3465 //// PlaceNormal(normal);
3466 SetColourFromGradient(static_gradient_hack
, factor
);
3467 PlaceVertex(a
, 0, 0);
3468 PlaceVertex(b
, w
, 0);
3469 PlaceVertex(c
, w
, h
);
3470 PlaceVertex(d
, 0, h
);
3471 EndQuadrilaterals();
3474 void GfxCore::SetColourFromLength(double length
, Double factor
)
3476 // Set the drawing colour based on log(length_of_leg).
3478 Double log_len
= log10(length
);
3479 Double how_far
= log_len
/ LOG_LEN_MAX
;
3480 how_far
= max(how_far
, 0.0);
3481 how_far
= min(how_far
, 1.0);
3482 SetColourFrom01(how_far
, factor
);
3485 void GfxCore::SetColourFrom01(double how_far
, Double factor
)
3488 double into_band
= modf(how_far
* (GetNumColourBands() - 1), &b
);
3490 GLAPen pen1
= GetPen(band
);
3491 // With 24bit colour, interpolating by less than this can have no effect.
3492 if (into_band
>= 1.0 / 512.0) {
3493 const GLAPen
& pen2
= GetPen(band
+ 1);
3494 pen1
.Interpolate(pen2
, into_band
);
3496 SetColour(pen1
, factor
);
3499 void GfxCore::AddPolylineLength(const traverse
& centreline
)
3501 vector
<PointInfo
>::const_iterator i
, prev_i
;
3502 i
= centreline
.begin();
3504 while (++i
!= centreline
.end()) {
3506 SetColourFromLength((*i
- *prev_i
).magnitude(), 1.0);
3507 PlaceVertex(*prev_i
);
3514 static double static_length_hack
; // FIXME
3516 void GfxCore::AddQuadrilateralLength(const Vector3
&a
, const Vector3
&b
,
3517 const Vector3
&c
, const Vector3
&d
)
3519 Vector3 normal
= (a
- c
) * (d
- b
);
3521 Double factor
= dot(normal
, light
) * .3 + .7;
3522 glaTexCoord
w(((b
- a
).magnitude() + (d
- c
).magnitude()) * .5);
3523 glaTexCoord
h(((b
- c
).magnitude() + (d
- a
).magnitude()) * .5);
3524 // FIXME: should plot triangles instead to avoid rendering glitches.
3525 BeginQuadrilaterals();
3526 //// PlaceNormal(normal);
3527 SetColourFromLength(static_length_hack
, factor
);
3528 PlaceVertex(a
, 0, 0);
3529 PlaceVertex(b
, w
, 0);
3530 PlaceVertex(c
, w
, h
);
3531 PlaceVertex(d
, 0, h
);
3532 EndQuadrilaterals();
3536 GfxCore::SkinPassage(vector
<XSect
> & centreline
, bool draw
)
3538 assert(centreline
.size() > 1);
3541 Vector3
last_right(1.0, 0.0, 0.0);
3543 // FIXME: it's not simple to set the colour of a tube based on error...
3544 // static_E_hack = something...
3545 vector
<XSect
>::iterator i
= centreline
.begin();
3546 vector
<XSect
>::size_type segment
= 0;
3547 while (i
!= centreline
.end()) {
3548 // get the coordinates of this vertex
3549 XSect
& pt_v
= *i
++;
3551 bool cover_end
= false;
3555 const Vector3
up_v(0.0, 0.0, 1.0);
3558 assert(i
!= centreline
.end());
3561 // get the coordinates of the next vertex
3562 const XSect
& next_pt_v
= *i
;
3564 // calculate vector from this pt to the next one
3565 Vector3 leg_v
= next_pt_v
- pt_v
;
3567 // obtain a vector in the LRUD plane
3568 right
= leg_v
* up_v
;
3569 if (right
.magnitude() == 0) {
3571 // Obtain a second vector in the LRUD plane,
3572 // perpendicular to the first.
3573 //up = right * leg_v;
3581 static_date_hack
= next_pt_v
.GetDate();
3582 } else if (segment
+ 1 == centreline
.size()) {
3585 // Calculate vector from the previous pt to this one.
3586 Vector3 leg_v
= pt_v
- prev_pt_v
;
3588 // Obtain a horizontal vector in the LRUD plane.
3589 right
= leg_v
* up_v
;
3590 if (right
.magnitude() == 0) {
3591 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
3592 // Obtain a second vector in the LRUD plane,
3593 // perpendicular to the first.
3594 //up = right * leg_v;
3602 static_date_hack
= pt_v
.GetDate();
3604 assert(i
!= centreline
.end());
3605 // Intermediate segment.
3607 // Get the coordinates of the next vertex.
3608 const XSect
& next_pt_v
= *i
;
3610 // Calculate vectors from this vertex to the
3611 // next vertex, and from the previous vertex to
3613 Vector3 leg1_v
= pt_v
- prev_pt_v
;
3614 Vector3 leg2_v
= next_pt_v
- pt_v
;
3616 // Obtain horizontal vectors perpendicular to
3617 // both legs, then normalise and average to get
3618 // a horizontal bisector.
3619 Vector3 r1
= leg1_v
* up_v
;
3620 Vector3 r2
= leg2_v
* up_v
;
3624 if (right
.magnitude() == 0) {
3625 // This is the "mid-pitch" case...
3628 if (r1
.magnitude() == 0) {
3631 // Rotate pitch section to minimise the
3632 // "tortional stress" - FIXME: use
3633 // triangles instead of rectangles?
3637 // Scale to unit vectors in the LRUD plane.
3640 Vector3 vec
= up
- right
;
3641 for (int orient
= 0; orient
<= 3; ++orient
) {
3642 Vector3 tmp
= U
[orient
] - prev_pt_v
;
3644 Double dotp
= dot(vec
, tmp
);
3645 if (dotp
> maxdotp
) {
3655 U
[2] = U
[shift
^ 2];
3656 U
[shift
^ 2] = temp
;
3663 // Check that the above code actually permuted
3664 // the vertices correctly.
3667 for (int j
= 0; j
<= 3; ++j
) {
3668 Vector3 tmp
= U
[j
] - prev_pt_v
;
3670 Double dotp
= dot(vec
, tmp
);
3671 if (dotp
> maxdotp
) {
3672 maxdotp
= dotp
+ 1e-6; // Add small tolerance to stop 45 degree offset cases being flagged...
3677 printf("New shift = %d!\n", shift
);
3680 for (int j
= 0; j
<= 3; ++j
) {
3681 Vector3 tmp
= U
[j
] - prev_pt_v
;
3683 Double dotp
= dot(vec
, tmp
);
3684 printf(" %d : %.8f\n", j
, dotp
);
3692 static_date_hack
= pt_v
.GetDate();
3695 // Scale to unit vectors in the LRUD plane.
3699 Double l
= fabs(pt_v
.GetL());
3700 Double r
= fabs(pt_v
.GetR());
3701 Double u
= fabs(pt_v
.GetU());
3702 Double d
= fabs(pt_v
.GetD());
3704 // Produce coordinates of the corners of the LRUD "plane".
3706 v
[0] = pt_v
- right
* l
+ up
* u
;
3707 v
[1] = pt_v
+ right
* r
+ up
* u
;
3708 v
[2] = pt_v
+ right
* r
- up
* d
;
3709 v
[3] = pt_v
- right
* l
- up
* d
;
3712 const Vector3
& delta
= pt_v
- prev_pt_v
;
3713 static_length_hack
= delta
.magnitude();
3714 static_gradient_hack
= delta
.gradient();
3716 (this->*AddQuad
)(v
[0], v
[1], U
[1], U
[0]);
3717 (this->*AddQuad
)(v
[2], v
[3], U
[3], U
[2]);
3718 (this->*AddQuad
)(v
[1], v
[2], U
[2], U
[1]);
3719 (this->*AddQuad
)(v
[3], v
[0], U
[0], U
[3]);
3724 (this->*AddQuad
)(v
[0], v
[1], v
[2], v
[3]);
3726 (this->*AddQuad
)(v
[3], v
[2], v
[1], v
[0]);
3737 pt_v
.set_right_bearing(deg(atan2(right
.GetY(), right
.GetX())));
3743 void GfxCore::FullScreenMode()
3745 m_Parent
->ViewFullScreen();
3748 bool GfxCore::IsFullScreen() const
3750 return m_Parent
->IsFullScreen();
3753 bool GfxCore::FullScreenModeShowingMenus() const
3755 return m_Parent
->FullScreenModeShowingMenus();
3758 void GfxCore::FullScreenModeShowMenus(bool show
)
3760 m_Parent
->FullScreenModeShowMenus(show
);
3764 GfxCore::MoveViewer(double forward
, double up
, double right
)
3766 double cT
= cos(rad(m_TiltAngle
));
3767 double sT
= sin(rad(m_TiltAngle
));
3768 double cP
= cos(rad(m_PanAngle
));
3769 double sP
= sin(rad(m_PanAngle
));
3770 Vector3
v_forward(cT
* sP
, cT
* cP
, sT
);
3771 Vector3
v_up(sT
* sP
, sT
* cP
, -cT
);
3772 Vector3
v_right(-cP
, sP
, 0);
3773 assert(fabs(dot(v_forward
, v_up
)) < 1e-6);
3774 assert(fabs(dot(v_forward
, v_right
)) < 1e-6);
3775 assert(fabs(dot(v_right
, v_up
)) < 1e-6);
3776 Vector3 move
= v_forward
* forward
+ v_up
* up
+ v_right
* right
;
3777 AddTranslation(-move
);
3778 // Show current position.
3779 m_Parent
->SetCoords(m_Parent
->GetOffset() - GetTranslation());
3783 PresentationMark
GfxCore::GetView() const
3785 return PresentationMark(GetTranslation() + m_Parent
->GetOffset(),
3786 m_PanAngle
, -m_TiltAngle
, m_Scale
);
3789 void GfxCore::SetView(const PresentationMark
& p
)
3792 SetTranslation(p
- m_Parent
->GetOffset());
3793 m_PanAngle
= p
.angle
;
3794 m_TiltAngle
= -p
.tilt_angle
; // FIXME: nasty reversed sense (and above)
3795 SetRotation(m_PanAngle
, m_TiltAngle
);
3800 void GfxCore::PlayPres(double speed
, bool change_speed
) {
3801 if (!change_speed
|| presentation_mode
== 0) {
3803 presentation_mode
= 0;
3806 presentation_mode
= PLAYING
;
3807 next_mark
= m_Parent
->GetPresMark(MARK_FIRST
);
3809 next_mark_time
= 0; // There already!
3810 this_mark_total
= 0;
3811 pres_reverse
= (speed
< 0);
3814 if (change_speed
) pres_speed
= speed
;
3817 bool new_pres_reverse
= (speed
< 0);
3818 if (new_pres_reverse
!= pres_reverse
) {
3819 pres_reverse
= new_pres_reverse
;
3821 next_mark
= m_Parent
->GetPresMark(MARK_PREV
);
3823 next_mark
= m_Parent
->GetPresMark(MARK_NEXT
);
3825 swap(this_mark_total
, next_mark_time
);
3830 void GfxCore::SetColourBy(int colour_by
) {
3831 m_ColourBy
= colour_by
;
3832 switch (colour_by
) {
3833 case COLOUR_BY_DEPTH
:
3834 AddQuad
= &GfxCore::AddQuadrilateralDepth
;
3835 AddPoly
= &GfxCore::AddPolylineDepth
;
3837 case COLOUR_BY_DATE
:
3838 AddQuad
= &GfxCore::AddQuadrilateralDate
;
3839 AddPoly
= &GfxCore::AddPolylineDate
;
3841 case COLOUR_BY_ERROR
:
3842 AddQuad
= &GfxCore::AddQuadrilateralError
;
3843 AddPoly
= &GfxCore::AddPolylineError
;
3845 case COLOUR_BY_GRADIENT
:
3846 AddQuad
= &GfxCore::AddQuadrilateralGradient
;
3847 AddPoly
= &GfxCore::AddPolylineGradient
;
3849 case COLOUR_BY_LENGTH
:
3850 AddQuad
= &GfxCore::AddQuadrilateralLength
;
3851 AddPoly
= &GfxCore::AddPolylineLength
;
3853 default: // case COLOUR_BY_NONE:
3854 AddQuad
= &GfxCore::AddQuadrilateral
;
3855 AddPoly
= &GfxCore::AddPolyline
;
3859 InvalidateList(LIST_UNDERGROUND_LEGS
);
3860 InvalidateList(LIST_SURFACE_LEGS
);
3861 InvalidateList(LIST_TUBES
);
3866 bool GfxCore::ExportMovie(const wxString
& fnm
)
3868 FILE* fh
= wxFopen(fnm
.fn_str(), wxT("wb"));
3870 wxGetApp().ReportError(wxString::Format(wmsg(/*Failed to open output file “%s”*/47), fnm
.c_str()));
3875 wxFileName::SplitPath(fnm
, NULL
, NULL
, NULL
, &ext
, wxPATH_NATIVE
);
3879 GetSize(&width
, &height
);
3880 // Round up to next multiple of 2 (required by ffmpeg).
3881 width
+= (width
& 1);
3882 height
+= (height
& 1);
3884 movie
= new MovieMaker();
3886 // movie takes ownership of fh.
3887 if (!movie
->Open(fh
, ext
.utf8_str(), width
, height
)) {
3888 wxGetApp().ReportError(wxString(movie
->get_error_string(), wxConvUTF8
));
3899 GfxCore::OnPrint(const wxString
&filename
, const wxString
&title
,
3900 const wxString
&datestamp
, time_t datestamp_numeric
,
3901 const wxString
&cs_proj
,
3902 bool close_after_print
)
3905 p
= new svxPrintDlg(m_Parent
, filename
, title
, cs_proj
,
3906 datestamp
, datestamp_numeric
,
3907 m_PanAngle
, m_TiltAngle
,
3908 m_Names
, m_Crosses
, m_Legs
, m_Surface
, m_Splays
,
3909 m_Tubes
, m_Entrances
, m_FixedPts
, m_ExportedPts
,
3910 true, close_after_print
);
3915 GfxCore::OnExport(const wxString
&filename
, const wxString
&title
,
3916 const wxString
&datestamp
, time_t datestamp_numeric
,
3917 const wxString
&cs_proj
)
3919 // Fill in "right_bearing" for each cross-section.
3920 list
<vector
<XSect
> >::iterator trav
= m_Parent
->tubes_begin();
3921 list
<vector
<XSect
> >::iterator tend
= m_Parent
->tubes_end();
3922 while (trav
!= tend
) {
3923 SkinPassage(*trav
, false);
3928 p
= new svxPrintDlg(m_Parent
, filename
, title
, cs_proj
,
3929 datestamp
, datestamp_numeric
,
3930 m_PanAngle
, m_TiltAngle
,
3931 m_Names
, m_Crosses
, m_Legs
, m_Surface
, m_Splays
,
3932 m_Tubes
, m_Entrances
, m_FixedPts
, m_ExportedPts
,
3938 make_cursor(const unsigned char * bits
, const unsigned char * mask
,
3941 #if defined __WXMSW__ || defined __WXMAC__
3943 // The default Mac cursor is black with a white edge, so
3944 // invert our custom cursors to match.
3946 for (int i
= 0; i
< 128; ++i
)
3947 b
[i
] = bits
[i
] ^ 0xff;
3949 const char * b
= reinterpret_cast<const char *>(bits
);
3951 wxBitmap
cursor_bitmap(b
, 32, 32);
3952 wxBitmap
mask_bitmap(reinterpret_cast<const char *>(mask
), 32, 32);
3953 cursor_bitmap
.SetMask(new wxMask(mask_bitmap
, *wxWHITE
));
3954 wxImage cursor_image
= cursor_bitmap
.ConvertToImage();
3955 cursor_image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
, hotx
);
3956 cursor_image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
, hoty
);
3957 return wxCursor(cursor_image
);
3959 return wxCursor((const char *)bits
, 32, 32, hotx
, hoty
,
3960 (const char *)mask
, wxBLACK
, wxWHITE
);
3967 #include "handmask.xbm"
3970 #include "brotate.xbm"
3972 #include "brotatemask.xbm"
3975 #include "vrotate.xbm"
3977 #include "vrotatemask.xbm"
3980 #include "rotate.xbm"
3982 #include "rotatemask.xbm"
3985 #include "rotatezoom.xbm"
3987 #include "rotatezoommask.xbm"
3990 GfxCore::UpdateCursor(GfxCore::cursor new_cursor
)
3992 // Check if we're already showing that cursor.
3993 if (current_cursor
== new_cursor
) return;
3995 current_cursor
= new_cursor
;
3996 switch (current_cursor
) {
3997 case GfxCore::CURSOR_DEFAULT
:
3998 GLACanvas::SetCursor(wxNullCursor
);
4000 case GfxCore::CURSOR_POINTING_HAND
:
4001 GLACanvas::SetCursor(wxCursor(wxCURSOR_HAND
));
4003 case GfxCore::CURSOR_DRAGGING_HAND
:
4004 GLACanvas::SetCursor(make_cursor(hand_bits
, handmask_bits
, 12, 18));
4006 case GfxCore::CURSOR_HORIZONTAL_RESIZE
:
4007 GLACanvas::SetCursor(wxCursor(wxCURSOR_SIZEWE
));
4009 case GfxCore::CURSOR_ROTATE_HORIZONTALLY
:
4010 GLACanvas::SetCursor(make_cursor(rotate_bits
, rotatemask_bits
, 15, 15));
4012 case GfxCore::CURSOR_ROTATE_VERTICALLY
:
4013 GLACanvas::SetCursor(make_cursor(vrotate_bits
, vrotatemask_bits
, 15, 15));
4015 case GfxCore::CURSOR_ROTATE_EITHER_WAY
:
4016 GLACanvas::SetCursor(make_cursor(brotate_bits
, brotatemask_bits
, 15, 15));
4018 case GfxCore::CURSOR_ZOOM
:
4019 GLACanvas::SetCursor(wxCursor(wxCURSOR_MAGNIFIER
));
4021 case GfxCore::CURSOR_ZOOM_ROTATE
:
4022 GLACanvas::SetCursor(make_cursor(rotatezoom_bits
, rotatezoommask_bits
, 15, 15));
4027 bool GfxCore::MeasuringLineActive() const
4029 if (Animating()) return false;
4030 return HereIsReal() || m_there
;
4033 bool GfxCore::HandleRClick(wxPoint point
)
4035 if (PointWithinCompass(point
)) {
4038 /* TRANSLATORS: View *looking* North */
4039 menu
.Append(menu_ORIENT_MOVE_NORTH
, wmsg(/*View &North*/240));
4040 /* TRANSLATORS: View *looking* East */
4041 menu
.Append(menu_ORIENT_MOVE_EAST
, wmsg(/*View &East*/241));
4042 /* TRANSLATORS: View *looking* South */
4043 menu
.Append(menu_ORIENT_MOVE_SOUTH
, wmsg(/*View &South*/242));
4044 /* TRANSLATORS: View *looking* West */
4045 menu
.Append(menu_ORIENT_MOVE_WEST
, wmsg(/*View &West*/243));
4046 menu
.AppendSeparator();
4047 /* TRANSLATORS: Menu item which turns off the "north arrow" in aven. */
4048 menu
.AppendCheckItem(menu_IND_COMPASS
, wmsg(/*&Hide Compass*/387));
4049 /* TRANSLATORS: tickable menu item in View menu.
4051 * Degrees are the angular measurement where there are 360 in a full
4053 menu
.AppendCheckItem(menu_CTL_DEGREES
, wmsg(/*&Degrees*/343));
4054 menu
.Connect(wxEVT_COMMAND_MENU_SELECTED
, (wxObjectEventFunction
)&wxEvtHandler::ProcessEvent
, NULL
, m_Parent
->GetEventHandler());
4059 if (PointWithinClino(point
)) {
4062 menu
.Append(menu_ORIENT_PLAN
, wmsg(/*&Plan View*/248));
4063 menu
.Append(menu_ORIENT_ELEVATION
, wmsg(/*Ele&vation*/249));
4064 menu
.AppendSeparator();
4065 /* TRANSLATORS: Menu item which turns off the tilt indicator in aven. */
4066 menu
.AppendCheckItem(menu_IND_CLINO
, wmsg(/*&Hide Clino*/384));
4067 /* TRANSLATORS: tickable menu item in View menu.
4069 * Degrees are the angular measurement where there are 360 in a full
4071 menu
.AppendCheckItem(menu_CTL_DEGREES
, wmsg(/*&Degrees*/343));
4072 /* TRANSLATORS: tickable menu item in View menu.
4074 * Show the tilt of the survey as a percentage gradient (100% = 45
4075 * degrees = 50 grad). */
4076 menu
.AppendCheckItem(menu_CTL_PERCENT
, wmsg(/*&Percent*/430));
4077 menu
.Connect(wxEVT_COMMAND_MENU_SELECTED
, (wxObjectEventFunction
)&wxEvtHandler::ProcessEvent
, NULL
, m_Parent
->GetEventHandler());
4082 if (PointWithinScaleBar(point
)) {
4085 /* TRANSLATORS: Menu item which turns off the scale bar in aven. */
4086 menu
.AppendCheckItem(menu_IND_SCALE_BAR
, wmsg(/*&Hide scale bar*/385));
4087 /* TRANSLATORS: tickable menu item in View menu.
4089 * "Metric" here means metres, km, etc (rather than feet, miles, etc)
4091 menu
.AppendCheckItem(menu_CTL_METRIC
, wmsg(/*&Metric*/342));
4092 menu
.Connect(wxEVT_COMMAND_MENU_SELECTED
, (wxObjectEventFunction
)&wxEvtHandler::ProcessEvent
, NULL
, m_Parent
->GetEventHandler());
4097 if (PointWithinColourKey(point
)) {
4100 menu
.AppendCheckItem(menu_COLOUR_BY_DEPTH
, wmsg(/*Colour by &Depth*/292));
4101 menu
.AppendCheckItem(menu_COLOUR_BY_DATE
, wmsg(/*Colour by D&ate*/293));
4102 menu
.AppendCheckItem(menu_COLOUR_BY_ERROR
, wmsg(/*Colour by &Error*/289));
4103 menu
.AppendCheckItem(menu_COLOUR_BY_GRADIENT
, wmsg(/*Colour by &Gradient*/85));
4104 menu
.AppendCheckItem(menu_COLOUR_BY_LENGTH
, wmsg(/*Colour by &Length*/82));
4105 menu
.AppendSeparator();
4106 /* TRANSLATORS: Menu item which turns off the colour key.
4107 * The "Colour Key" is the thing in aven showing which colour
4108 * corresponds to which depth, date, survey closure error, etc. */
4109 menu
.AppendCheckItem(menu_IND_COLOUR_KEY
, wmsg(/*&Hide colour key*/386));
4110 if (m_ColourBy
== COLOUR_BY_DEPTH
|| m_ColourBy
== COLOUR_BY_LENGTH
)
4111 menu
.AppendCheckItem(menu_CTL_METRIC
, wmsg(/*&Metric*/342));
4112 else if (m_ColourBy
== COLOUR_BY_GRADIENT
)
4113 menu
.AppendCheckItem(menu_CTL_DEGREES
, wmsg(/*&Degrees*/343));
4114 menu
.Connect(wxEVT_COMMAND_MENU_SELECTED
, (wxObjectEventFunction
)&wxEvtHandler::ProcessEvent
, NULL
, m_Parent
->GetEventHandler());
4122 void GfxCore::SetZoomBox(wxPoint p1
, wxPoint p2
, bool centred
, bool aspect
)
4125 p1
.x
= p2
.x
+ (p1
.x
- p2
.x
) * 2;
4126 p1
.y
= p2
.y
+ (p1
.y
- p2
.y
) * 2;
4129 #if 0 // FIXME: This needs more work.
4130 int sx
= GetXSize();
4131 int sy
= GetYSize();
4132 int dx
= p1
.x
- p2
.x
;
4133 int dy
= p1
.y
- p2
.y
;
4134 int dy_new
= dx
* sy
/ sx
;
4135 if (abs(dy_new
) >= abs(dy
)) {
4136 p1
.y
+= (dy_new
- dy
) / 2;
4137 p2
.y
-= (dy_new
- dy
) / 2;
4139 int dx_new
= dy
* sx
/ sy
;
4140 p1
.x
+= (dx_new
- dx
) / 2;
4141 p2
.x
-= (dx_new
- dx
) / 2;
4145 zoombox
.set(p1
, p2
);
4149 void GfxCore::ZoomBoxGo()
4151 if (!zoombox
.active()) return;
4153 int width
= GetXSize();
4154 int height
= GetYSize();
4156 TranslateCave(-0.5 * (zoombox
.x1
+ zoombox
.x2
- width
),
4157 -0.5 * (zoombox
.y1
+ zoombox
.y2
- height
));
4158 int box_w
= abs(zoombox
.x1
- zoombox
.x2
);
4159 int box_h
= abs(zoombox
.y1
- zoombox
.y2
);
4161 double factor
= min(double(width
) / box_w
, double(height
) / box_h
);
4165 SetScale(GetScale() * factor
);