source: git/src/gfxcore.h @ 5a7597a

RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since 5a7597a was 381ae6e, checked in by Olly Betts <olly@…>, 10 years ago

lib/survex.pot,src/: Make measuring line work from anonymous
stations properly. (Fixes #44)

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