source: git/src/gfxcore.h @ af50685

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since af50685 was af50685, checked in by Olly Betts <olly@…>, 9 years ago

lib/survex.pot,src/: Add "Colour by Length".

  • Property mode set to 100644
File size: 15.7 KB
Line 
1//
2//  gfxcore.h
3//
4//  Core drawing code for Aven.
5//
6//  Copyright (C) 2000-2001,2002,2005 Mark R. Shinwell.
7//  Copyright (C) 2001-2004,2005,2006,2007,2010,2011,2012,2013,2014,2015 Olly Betts
8//  Copyright (C) 2005 Martin Green
9//
10//  This program is free software; you can redistribute it and/or modify
11//  it under the terms of the GNU General Public License as published by
12//  the Free Software Foundation; either version 2 of the License, or
13//  (at your option) any later version.
14//
15//  This program is distributed in the hope that it will be useful,
16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18//  GNU General Public License for more details.
19//
20//  You should have received a copy of the GNU General Public License
21//  along with this program; if not, write to the Free Software
22//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23//
24
25#ifndef gfxcore_h
26#define gfxcore_h
27
28#include <float.h>
29#include <limits.h>
30#include <time.h>
31
32#include "img_hosted.h"
33
34#include "guicontrol.h"
35#include "labelinfo.h"
36#include "vector3.h"
37#include "wx.h"
38#include "gla.h"
39
40#include <list>
41#include <utility>
42#include <vector>
43
44using namespace std;
45
46class MainFrm;
47class traverse;
48
49class XSect;
50class PointInfo;
51class MovieMaker;
52
53class PresentationMark : public Point {
54  public:
55    Double angle, tilt_angle;
56    Double scale;
57    Double time;
58    PresentationMark() : Point(), angle(0), tilt_angle(0), scale(0), time(0)
59        { }
60    PresentationMark(const Vector3 & v, Double angle_, Double tilt_angle_,
61                     Double scale_, Double time_ = 0)
62        : Point(v), angle(angle_), tilt_angle(tilt_angle_), scale(scale_),
63          time(time_)
64        { }
65    bool is_valid() const { return scale > 0; }
66};
67
68struct ZoomBox {
69  public:
70    int x1, y1, x2, y2;
71
72    ZoomBox()
73        : x1(INT_MAX) { }
74
75    bool active() const { return x1 != INT_MAX; }
76
77    void set(const wxPoint & p1, const wxPoint & p2) {
78        x1 = p1.x;
79        y1 = p1.y;
80        x2 = p2.x;
81        y2 = p2.y;
82    }
83
84    void unset() {
85        x1 = INT_MAX;
86    }
87};
88
89enum {
90    COLOUR_BY_NONE,
91    COLOUR_BY_DEPTH,
92    COLOUR_BY_DATE,
93    COLOUR_BY_ERROR,
94    COLOUR_BY_LENGTH,
95    COLOUR_BY_LIMIT_ // Leave this last.
96};
97
98enum {
99    UPDATE_NONE,
100    UPDATE_BLOBS,
101    UPDATE_BLOBS_AND_CROSSES
102};
103
104enum {
105      SPLAYS_HIDE,
106      SPLAYS_SHOW_FADED,
107      SPLAYS_SHOW_NORMAL,
108};
109
110// It's pointless to redraw the screen as often as we can on a fast machine,
111// since the display hardware will only update so many times per second.
112// This is the maximum framerate we'll redraw at.
113const int MAX_FRAMERATE = 50;
114
115class GfxCore : public GLACanvas {
116    Double m_Scale;
117    int m_ScaleBarWidth;
118
119    typedef enum {
120        LIST_COMPASS,
121        LIST_CLINO,
122        LIST_CLINO_BACK,
123        LIST_SCALE_BAR,
124        LIST_DEPTH_KEY,
125        LIST_DATE_KEY,
126        LIST_ERROR_KEY,
127        LIST_LENGTH_KEY,
128        LIST_UNDERGROUND_LEGS,
129        LIST_TUBES,
130        LIST_SURFACE_LEGS,
131        LIST_BLOBS,
132        LIST_CROSSES,
133        LIST_GRID,
134        LIST_SHADOW,
135        LIST_LIMIT_ // Leave this last.
136    } drawing_list;
137
138    static const int NUM_COLOUR_BANDS = 13;
139
140    void SetPanBase() {
141        base_pan = m_PanAngle;
142        base_pan_time = timer.Time() - (1000 / MAX_FRAMERATE);
143    }
144
145    void SetTiltBase() {
146        base_tilt = m_TiltAngle;
147        base_tilt_time = timer.Time() - (1000 / MAX_FRAMERATE);
148    }
149
150public:
151    typedef enum {
152        CURSOR_DEFAULT,
153        CURSOR_POINTING_HAND,
154        CURSOR_DRAGGING_HAND,
155        CURSOR_HORIZONTAL_RESIZE,
156        CURSOR_ROTATE_HORIZONTALLY,
157        CURSOR_ROTATE_VERTICALLY,
158        CURSOR_ROTATE_EITHER_WAY,
159        CURSOR_ZOOM,
160        CURSOR_ZOOM_ROTATE
161    } cursor;
162
163private:
164    GUIControl* m_Control;
165    char* m_LabelGrid;
166    MainFrm* m_Parent;
167    bool m_DoneFirstShow;
168    Double m_TiltAngle;
169    Double m_PanAngle;
170    bool m_Rotating;
171    Double m_RotationStep;
172    int m_SwitchingTo;
173    bool m_Crosses;
174    bool m_Legs;
175    int m_Splays;
176    bool m_Names;
177    bool m_Scalebar;
178    bool m_ColourKey;
179    bool m_OverlappingNames;
180    bool m_Compass;
181    bool m_Clino;
182    bool m_Tubes;
183    int m_ColourBy;
184
185    bool m_HaveData;
186    bool m_MouseOutsideCompass;
187    bool m_MouseOutsideElev;
188    bool m_Surface;
189    bool m_Entrances;
190    bool m_FixedPts;
191    bool m_ExportedPts;
192    bool m_Grid;
193    bool m_BoundingBox;
194
195    bool m_Degrees;
196    bool m_Metric;
197    bool m_Percent;
198
199    bool m_HitTestDebug;
200
201    list<LabelInfo*> *m_PointGrid;
202    bool m_HitTestGridValid;
203
204    LabelInfo temp_here;
205    const LabelInfo * m_here;
206    const LabelInfo * m_there;
207
208    wxStopWatch timer;
209    long base_tilt_time;
210    long base_pan_time;
211    Double base_tilt;
212    Double base_pan;
213
214    GLAPen m_Pens[NUM_COLOUR_BANDS + 1];
215
216#define PLAYING 1
217    int presentation_mode; // for now, 0 => off, PLAYING => continuous play
218    bool pres_reverse;
219    double pres_speed;
220    PresentationMark next_mark;
221    double next_mark_time;
222    double this_mark_total;
223
224    MovieMaker * movie;
225
226    cursor current_cursor;
227
228    int sqrd_measure_threshold;
229
230    // The legends for each entry in the colour key.
231    wxString key_legends[NUM_COLOUR_BANDS];
232
233    wxPoint key_lowerleft[COLOUR_BY_LIMIT_];
234
235    ZoomBox zoombox;
236
237    void PlaceVertexWithColour(const Vector3 &v, Double factor = 1.0);
238    void PlaceVertexWithColour(const Vector3 & v, GLint tex_x, GLint tex_y,
239                               Double factor);
240    void SetDepthColour(Double z, Double factor);
241    void PlaceVertexWithDepthColour(const Vector3 & v, Double factor = 1.0);
242    void PlaceVertexWithDepthColour(const Vector3 & v, GLint tex_x, GLint tex_y, Double factor);
243
244    void SetColourFromDate(int date, Double factor);
245    void SetColourFromError(double E, Double factor);
246    void SetColourFromLength(double len, Double factor);
247
248    int GetClinoOffset() const;
249    void DrawTick(int angle_cw);
250    void DrawArrow(gla_colour col1, gla_colour col2);
251
252    void SkinPassage(vector<XSect> & centreline, bool draw = true);
253
254    virtual void GenerateList(unsigned int l);
255    void GenerateDisplayList();
256    void GenerateDisplayListTubes();
257    void GenerateDisplayListSurface();
258    void GenerateDisplayListShadow();
259    void GenerateBlobsDisplayList();
260
261    void DrawIndicators();
262
263    void TryToFreeArrays();
264    void FirstShow();
265
266    void DrawScaleBar();
267    void DrawColourKey(int num_bands, const wxString & other, const wxString & units);
268    void DrawDepthKey();
269    void DrawDateKey();
270    void DrawErrorKey();
271    void DrawLengthKey();
272    void DrawCompass();
273    void DrawClino();
274    void DrawClinoBack();
275    void Draw2dIndicators();
276    void DrawGrid();
277
278    void NattyDrawNames();
279    void SimpleDrawNames();
280
281    void DefaultParameters();
282
283    void Repaint();
284
285    void CreateHitTestGrid();
286
287    int GetCompassXPosition() const;
288    int GetClinoXPosition() const;
289    int GetIndicatorYPosition() const;
290    int GetIndicatorRadius() const;
291
292    void ToggleFlag(bool* flag, int update = UPDATE_NONE);
293
294    const GLAPen& GetPen(int band) const {
295        assert(band >= 0 && band < NUM_COLOUR_BANDS);
296        return m_Pens[band];
297    }
298
299    const GLAPen& GetSurfacePen() const { return m_Pens[NUM_COLOUR_BANDS]; }
300
301    int GetNumColourBands() const { return NUM_COLOUR_BANDS; }
302
303    void DrawShadowedBoundingBox();
304    void DrawBoundingBox();
305
306public:
307    GfxCore(MainFrm* parent, wxWindow* parent_window, GUIControl* control);
308    ~GfxCore();
309
310    void Initialise(bool same_file);
311    void InitialiseTerrain();
312
313    void UpdateBlobs();
314    void ForceRefresh();
315
316    void RefreshLine(const Point* a, const Point* b, const Point* c);
317
318    void SetHereFromTree(const LabelInfo * p);
319
320    void SetHere();
321    void SetHere(const LabelInfo * p);
322    void SetThere();
323    void SetThere(const LabelInfo * p);
324
325    void CentreOn(const Point &p);
326
327    void TranslateCave(int dx, int dy);
328    void TiltCave(Double tilt_angle);
329    void TurnCave(Double angle);
330    void TurnCaveTo(Double angle);
331
332    void OnPaint(wxPaintEvent&);
333    void OnSize(wxSizeEvent& event);
334    void OnIdle(wxIdleEvent& event);
335
336    void OnMouseMove(wxMouseEvent& event) { m_Control->OnMouseMove(event); }
337    void OnLeaveWindow(wxMouseEvent& event);
338
339    void OnLButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnLButtonDown(event); }
340    void OnLButtonUp(wxMouseEvent& event) { m_Control->OnLButtonUp(event); }
341    void OnMButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnMButtonDown(event); }
342    void OnMButtonUp(wxMouseEvent& event) { m_Control->OnMButtonUp(event); }
343    void OnRButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnRButtonDown(event); }
344    void OnRButtonUp(wxMouseEvent& event) { m_Control->OnRButtonUp(event); }
345    void OnMouseWheel(wxMouseEvent& event) { SetFocus(); m_Control->OnMouseWheel(event); }
346    void OnKeyPress(wxKeyEvent &event) { m_Control->OnKeyPress(event); }
347
348    void Animate();
349    bool Animating() const {
350        return m_Rotating || m_SwitchingTo || presentation_mode != 0;
351    }
352
353    void ClearCoords();
354    void SetCoords(wxPoint);
355
356    // Determine whether the compass is currently shown.
357    bool ShowingCompass() const { return m_Compass; }
358    // Determine whether the clino is currently shown.
359    bool ShowingClino() const { return m_Clino; }
360
361    bool PointWithinCompass(wxPoint point) const;
362    bool PointWithinClino(wxPoint point) const;
363    bool PointWithinScaleBar(wxPoint point) const;
364    bool PointWithinColourKey(wxPoint point) const;
365
366    void SetCompassFromPoint(wxPoint point);
367    void SetClinoFromPoint(wxPoint point);
368    void SetScaleBarFromOffset(wxCoord dx);
369
370    void RedrawIndicators();
371
372    void StartRotation();
373    void ToggleRotation();
374    void StopRotation();
375    bool IsExtendedElevation() const;
376    void ReverseRotation();
377    void RotateSlower(bool accel);
378    void RotateFaster(bool accel);
379
380    void SwitchToElevation();
381    void SwitchToPlan();
382
383    void SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax);
384
385    double GetCompassValue() const { return m_PanAngle; }
386    bool ShowingPlan() const;
387    bool ShowingElevation() const;
388    bool ShowingMeasuringLine() const;
389    bool HereIsReal() const { return m_here && m_here != &temp_here; }
390
391    bool CanRaiseViewpoint() const;
392    bool CanLowerViewpoint() const;
393
394    bool IsRotating() const { return m_Rotating; }
395    bool HasData() const { return m_DoneFirstShow && m_HaveData; }
396    bool HasDepth() const;
397    bool HasErrorInformation() const;
398    bool HasDateInformation() const;
399
400    double GetScale() const { return m_Scale; }
401    void SetScale(Double scale);
402
403    bool ShowingStationNames() const { return m_Names; }
404    bool ShowingOverlappingNames() const { return m_OverlappingNames; }
405    bool ShowingCrosses() const { return m_Crosses; }
406    bool ShowingGrid() const { return m_Grid; }
407
408    int ColouringBy() const { return m_ColourBy; }
409
410    bool HasUndergroundLegs() const;
411    bool HasSplays() const;
412    bool HasSurfaceLegs() const;
413    bool HasTubes() const;
414
415    bool ShowingUndergroundLegs() const { return m_Legs; }
416    int ShowingSplaysMode() const { return m_Splays; }
417    bool ShowingSurfaceLegs() const { return m_Surface; }
418
419    bool ShowingColourKey() const { return m_ColourKey; }
420    bool ShowingScaleBar() const { return m_Scalebar; }
421
422    bool ShowingEntrances() const { return m_Entrances; }
423    bool ShowingFixedPts() const { return m_FixedPts; }
424    bool ShowingExportedPts() const { return m_ExportedPts; }
425
426    int GetNumEntrances() const;
427    int GetNumFixedPts() const;
428    int GetNumExportedPts() const;
429
430    void ToggleUndergroundLegs() {
431        ToggleFlag(&m_Legs, UPDATE_BLOBS_AND_CROSSES);
432    }
433    void SetSplaysMode(int mode) {
434        m_Splays = mode;
435        UpdateBlobs();
436        InvalidateList(LIST_UNDERGROUND_LEGS);
437        ForceRefresh();
438    }
439    void ToggleSurfaceLegs() {
440        ToggleFlag(&m_Surface, UPDATE_BLOBS_AND_CROSSES);
441    }
442    void ToggleCompass() {
443        ToggleFlag(&m_Compass);
444        InvalidateList(LIST_SCALE_BAR);
445    }
446    void ToggleClino() {
447        ToggleFlag(&m_Clino);
448        InvalidateList(LIST_SCALE_BAR);
449    }
450    void ToggleScaleBar() { ToggleFlag(&m_Scalebar); }
451    void ToggleEntrances() { ToggleFlag(&m_Entrances, UPDATE_BLOBS); }
452    void ToggleFixedPts() { ToggleFlag(&m_FixedPts, UPDATE_BLOBS); }
453    void ToggleExportedPts() { ToggleFlag(&m_ExportedPts, UPDATE_BLOBS); }
454    void ToggleGrid() { ToggleFlag(&m_Grid); }
455    void ToggleCrosses() { ToggleFlag(&m_Crosses); }
456    void ToggleStationNames() { ToggleFlag(&m_Names); }
457    void ToggleOverlappingNames() { ToggleFlag(&m_OverlappingNames); }
458    void ToggleColourKey() { ToggleFlag(&m_ColourKey); }
459    void ToggleMetric() {
460        ToggleFlag(&m_Metric);
461        InvalidateList(LIST_DEPTH_KEY);
462        InvalidateList(LIST_SCALE_BAR);
463    }
464    void ToggleHitTestDebug() {
465        ToggleFlag(&m_HitTestDebug);
466    }
467    void ToggleDegrees() { ToggleFlag(&m_Degrees); }
468    void TogglePercent() { ToggleFlag(&m_Percent); }
469    void ToggleTubes() { ToggleFlag(&m_Tubes); }
470    void TogglePerspective() { GLACanvas::TogglePerspective(); ForceRefresh(); }
471    void ToggleSmoothShading();
472    bool DisplayingBoundingBox() const { return m_BoundingBox; }
473    void ToggleBoundingBox() { ToggleFlag(&m_BoundingBox); }
474    void ToggleFatFinger();
475
476    bool GetMetric() const { return m_Metric; }
477    bool GetDegrees() const { return m_Degrees; }
478    bool GetPercent() const { return m_Percent; }
479    bool GetTubes() const { return m_Tubes; }
480
481    bool CheckHitTestGrid(const wxPoint& point, bool centre);
482
483    void ClearTreeSelection();
484
485    void Defaults();
486
487    void FullScreenMode();
488
489    bool IsFullScreen() const;
490
491    bool FullScreenModeShowingMenus() const;
492
493    void FullScreenModeShowMenus(bool show);
494
495    void DragFinished();
496
497    void SplitLineAcrossBands(int band, int band2,
498                              const Vector3 &p, const Vector3 &q,
499                              Double factor = 1.0);
500    int GetDepthColour(Double z) const;
501    Double GetDepthBoundaryBetweenBands(int a, int b) const;
502    void AddPolyline(const traverse & centreline);
503    void AddPolylineDepth(const traverse & centreline);
504    void AddPolylineDate(const traverse & centreline);
505    void AddPolylineError(const traverse & centreline);
506    void AddPolylineLength(const traverse & centreline);
507    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
508                          const Vector3 &c, const Vector3 &d);
509    void AddPolylineShadow(const traverse & centreline);
510    void AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b,
511                               const Vector3 &c, const Vector3 &d);
512    void AddQuadrilateralDate(const Vector3 &a, const Vector3 &b,
513                              const Vector3 &c, const Vector3 &d);
514    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
515                               const Vector3 &c, const Vector3 &d);
516    void AddQuadrilateralLength(const Vector3 &a, const Vector3 &b,
517                                const Vector3 &c, const Vector3 &d);
518    void MoveViewer(double forward, double up, double right);
519
520    void (GfxCore::* AddQuad)(const Vector3 &a, const Vector3 &b,
521                              const Vector3 &c, const Vector3 &d);
522    void (GfxCore::* AddPoly)(const traverse & centreline);
523
524    PresentationMark GetView() const;
525    void SetView(const PresentationMark & p);
526    void PlayPres(double speed, bool change_speed = true);
527    int GetPresentationMode() const { return presentation_mode; }
528    double GetPresentationSpeed() const { return presentation_mode ? pres_speed : 0; }
529
530    void SetColourBy(int colour_by);
531    bool ExportMovie(const wxString & fnm);
532    void OnPrint(const wxString &filename, const wxString &title,
533                 const wxString &datestamp, time_t datestamp_numeric,
534                 const wxString &cs_proj,
535                 bool close_after_print = false);
536    void OnExport(const wxString &filename, const wxString &title,
537                  const wxString &datestamp, time_t datestamp_numeric,
538                  const wxString &cs_proj);
539    void UpdateCursor(GfxCore::cursor new_cursor);
540    bool MeasuringLineActive() const;
541
542    bool HandleRClick(wxPoint point);
543
544    void InvalidateAllLists() {
545        for (int i = 0; i < LIST_LIMIT_; ++i) {
546            InvalidateList(i);
547        }
548    }
549
550    void SetZoomBox(wxPoint p1, wxPoint p2, bool centred, bool aspect);
551
552    void UnsetZoomBox() {
553        if (!zoombox.active()) return;
554        zoombox.unset();
555        ForceRefresh();
556    }
557
558    void ZoomBoxGo();
559
560private:
561    DECLARE_EVENT_TABLE()
562};
563
564#endif
Note: See TracBrowser for help on using the repository browser.