source: git/src/gfxcore.h @ f6d1b6fd

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since f6d1b6fd was 242cb07, checked in by Olly Betts <olly@…>, 10 years ago

src/: Rename methods which hide virtual methods in the parent class.
Reported by Martin Sluka.

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