source: git/src/gfxcore.h @ 5293c84

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since 5293c84 was 5293c84, checked in by Olly Betts <olly@…>, 14 years ago

Declare constants with enum rather than #define so they automatically get
allocated unique values, and so they show up in the debugger.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3362 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 12.9 KB
RevLine 
[5809313]1//
2//  gfxcore.h
3//
4//  Core drawing code for Aven.
5//
[f4c5932]6//  Copyright (C) 2000-2001,2002,2005 Mark R. Shinwell.
[08253d9]7//  Copyright (C) 2001-2004,2005,2006,2007 Olly Betts
[887c26e]8//  Copyright (C) 2005 Martin Green
[5809313]9//
10//  This program is free software; you can redistribute it and/or modify
11//  it under the terms of the GNU General Public License as published by
12//  the Free Software Foundation; either version 2 of the License, or
13//  (at your option) any later version.
14//
15//  This program is distributed in the hope that it will be useful,
16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18//  GNU General Public License for more details.
19//
20//  You should have received a copy of the GNU General Public License
21//  along with this program; if not, write to the Free Software
[5940815]22//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
[5809313]23//
24
25#ifndef gfxcore_h
26#define gfxcore_h
27
[7aa15c0]28#include <float.h>
29
[db36155]30#include "img.h"
31
[5876fcb]32#include "guicontrol.h"
[4a0e6b35]33#include "vector3.h"
[5809313]34#include "wx.h"
[33b2094]35#include "gla.h"
[3ddcad8]36
[156dc16]37#include <list>
[3ddcad8]38#include <utility>
39#include <vector>
[5809313]40
[3ddcad8]41using namespace std;
[003d953]42
[137bf99]43class MainFrm;
[c61aa79]44class traverse;
[5809313]45
[0e69efe]46extern const int NUM_DEPTH_COLOURS;
47
[d67450e]48class Point : public Vector3 {
[4a0e6b35]49  public:
[cd6ea75]50    Point() {}
[d67450e]51    Point(const Vector3 & v) : Vector3(v) { }
52    Point(const img_point & pt) : Vector3(pt.x, pt.y, pt.z) { }
[4a0e6b35]53    Double GetX() const { return x; }
54    Double GetY() const { return y; }
55    Double GetZ() const { return z; }
[d67450e]56    void Invalidate() { x = DBL_MAX; }
57    bool IsValid() const { return x != DBL_MAX; }
[2a02de2]58};
59
[ee05463]60class XSect;
[39e460c9]61class LabelInfo;
[d4650b3]62class PointInfo;
[6a4cdcb6]63class MovieMaker;
[39e460c9]64
[4a0e6b35]65class PresentationMark : public Point {
66  public:
[1690fa9]67    Double angle, tilt_angle;
68    Double scale;
[49ce5b0]69    Double time;
[4a0e6b35]70    PresentationMark() : Point(), angle(0), tilt_angle(0), scale(0), time(0)
[1690fa9]71        { }
[d67450e]72    PresentationMark(const Vector3 & v, Double angle_, Double tilt_angle_,
73                     Double scale_, Double time_ = 0)
74        : Point(v), angle(angle_), tilt_angle(tilt_angle_), scale(scale_),
75          time(time_)
[1690fa9]76        { }
77    bool is_valid() const { return scale > 0; }
78};
79
[5293c84]80enum {
81    COLOUR_BY_NONE,
82    COLOUR_BY_DEPTH,
83    COLOUR_BY_DATE,
84    COLOUR_BY_ERROR
85};
86
87enum {
88    UPDATE_NONE,
89    UPDATE_BLOBS,
90    UPDATE_BLOBS_AND_CROSSES
91};
[9cf3688]92
[33b2094]93class GfxCore : public GLACanvas {
[5b7164d]94    Double m_Scale;
[e2c1671]95    int m_ScaleBarWidth;
[42adb19]96
[d2fcc9b]97    typedef enum {
[fe665c4]98        LIST_COMPASS,
99        LIST_CLINO,
100        LIST_CLINO_BACK,
[252d759]101        LIST_DEPTHBAR,
[d4650b3]102        LIST_DATEBAR,
[c61aa79]103        LIST_ERRORBAR,
[d2fcc9b]104        LIST_UNDERGROUND_LEGS,
105        LIST_TUBES,
106        LIST_SURFACE_LEGS,
[37d7084]107        LIST_BLOBS,
[8bd480e]108        LIST_CROSSES,
[37d7084]109        LIST_GRID,
110        LIST_SHADOW
[d2fcc9b]111    } drawing_list;
[7aa15c0]112
[e2c1671]113public:
114    typedef enum {
115        CURSOR_DEFAULT,
116        CURSOR_POINTING_HAND,
117        CURSOR_DRAGGING_HAND,
118        CURSOR_HORIZONTAL_RESIZE,
119        CURSOR_ROTATE_HORIZONTALLY,
120        CURSOR_ROTATE_VERTICALLY,
121        CURSOR_ROTATE_EITHER_WAY,
[ecf2d23]122        CURSOR_ZOOM,
123        CURSOR_ZOOM_ROTATE
[e2c1671]124    } cursor;
125
126private:
[5876fcb]127    GUIControl* m_Control;
[33b2094]128    char* m_LabelGrid;
[137bf99]129    MainFrm* m_Parent;
[5809313]130    bool m_DoneFirstShow;
[c6d95d8]131    Double m_TiltAngle;
132    Double m_PanAngle;
[5809313]133    bool m_Rotating;
[c6d95d8]134    Double m_RotationStep;
[3d00693]135    int m_SwitchingTo;
[5809313]136    bool m_Crosses;
137    bool m_Legs;
138    bool m_Names;
139    bool m_Scalebar;
140    bool m_Depthbar;
141    bool m_OverlappingNames;
142    bool m_Compass;
[c300a04]143    bool m_Clino;
[33b2094]144    bool m_Tubes;
[5809313]145    int m_XSize;
146    int m_YSize;
[da6c802]147    int m_ColourBy;
[a7708927]148
149    bool m_HaveData;
[b56df45]150    bool m_MouseOutsideCompass;
151    bool m_MouseOutsideElev;
[e8bc148]152    bool m_Surface;
[fe444b8]153    bool m_Entrances;
154    bool m_FixedPts;
155    bool m_ExportedPts;
[c1cf79d]156    bool m_Grid;
[f4c5932]157    bool m_BoundingBox;
[fa42426]158
[33b2094]159    bool m_Degrees;
160    bool m_Metric;
161
[fa42426]162    list<LabelInfo*> *m_PointGrid;
[dfe4454c]163    bool m_HitTestGridValid;
[156dc16]164
[c00c6713]165    bool m_here_is_temporary;
[ef07952]166    Point m_here, m_there;
[156dc16]167
[a8e9fde]168    wxStopWatch timer;
169    long drawtime;
[9cf3688]170
[0e69efe]171    GLAPen * m_Pens;
172
[1690fa9]173#define PLAYING 1
174    int presentation_mode; // for now, 0 => off, PLAYING => continuous play
[128fac4]175    bool pres_reverse;
176    double pres_speed;
[1690fa9]177    PresentationMark next_mark;
178    double next_mark_time;
[128fac4]179    double this_mark_total;
[6a4cdcb6]180
181    MovieMaker * mpeg;
182
[e2c1671]183    cursor current_cursor;
184
[d67450e]185    void PlaceVertexWithColour(const Vector3 &v, Double factor = 1.0);
186    void PlaceVertexWithDepthColour(const Vector3 & v, Double factor = 1.0);
[da6c802]187
[d4650b3]188    void SetColourFromDate(time_t date, Double factor);
[c61aa79]189    void SetColourFromError(double E, Double factor);
[d4650b3]190
[1eeb55a]191    int GetClinoOffset() const;
[fe665c4]192    void DrawTick(int angle_cw);
[d67450e]193    void DrawArrow(gla_colour col1, gla_colour col2);
[c6d95d8]194    wxString FormatLength(Double, bool scalebar = true);
[5809313]195
[ee05463]196    void SkinPassage(const vector<XSect> & centreline);
[33b2094]197
[d2fcc9b]198    virtual void GenerateList(unsigned int l);
[33b2094]199    void GenerateDisplayList();
[9eb58d0]200    void GenerateDisplayListTubes();
[33b2094]201    void GenerateDisplayListSurface();
[37d7084]202    void GenerateDisplayListShadow();
[d9b3270]203    void GenerateBlobsDisplayList();
[6747314]204
205    void DrawIndicators();
[33b2094]206
[5809313]207    void TryToFreeArrays();
208    void FirstShow();
[84cab34]209
210    void DrawScalebar();
211    void DrawDepthbar();
[d4650b3]212    void DrawDatebar();
[c61aa79]213    void DrawErrorbar();
[fe665c4]214    void DrawCompass();
215    void DrawClino();
216    void DrawClinoBack();
[6606406]217    void Draw2dIndicators();
[c1cf79d]218    void DrawGrid();
[6606406]219
[84cab34]220    void NattyDrawNames();
221    void SimpleDrawNames();
222
[de7a879]223    void DefaultParameters();
[5809313]224
[0e864da5]225    void Repaint();
226
[dfe4454c]227    void CreateHitTestGrid();
[421b7d2]228
[1eeb55a]229    int GetCompassXPosition() const;
230    int GetClinoXPosition() const;
231    int GetIndicatorYPosition() const;
232    int GetIndicatorRadius() const;
[5876fcb]233
[eff44b9]234    void ToggleFlag(bool* flag, int update = UPDATE_NONE);
[5876fcb]235
[0e69efe]236    GLAPen& GetPen(int band) const {
237        assert(band >= 0 && band < NUM_DEPTH_COLOURS);
238        return m_Pens[band];
239    }
240
241    GLAPen& GetSurfacePen() const { return m_Pens[NUM_DEPTH_COLOURS]; }
242
243    int GetNumDepthBands() const { return NUM_DEPTH_COLOURS; }
244
[f4c5932]245    void DrawShadowedBoundingBox();
246    void DrawBoundingBox();
247
[5809313]248public:
[5876fcb]249    GfxCore(MainFrm* parent, wxWindow* parent_window, GUIControl* control);
[5809313]250    ~GfxCore();
251
[0c6bf5e8]252    void Initialise(bool same_file);
[8000d8f]253    void InitialiseTerrain();
[a87b1f7]254
[429465a]255    void UpdateBlobs();
[fa42426]256    void ForceRefresh();
[156dc16]257
[0580c6a]258    void RefreshLine(const Point& a, const Point& b, const Point& c);
[9cf3688]259
[fd6e0d5]260    void SetHere();
[82c3731]261    void SetHere(const Point &p);
[fd6e0d5]262    void SetThere();
[82c3731]263    void SetThere(const Point &p);
[fd6e0d5]264
[82c3731]265    void CentreOn(const Point &p);
[156dc16]266
[5876fcb]267    void TranslateCave(int dx, int dy);
268    void TiltCave(Double tilt_angle);
269    void TurnCave(Double angle);
270    void TurnCaveTo(Double angle);
271
272    void OnPaint(wxPaintEvent&);
273    void OnSize(wxSizeEvent& event);
[6e4a123]274    void OnIdle(wxIdleEvent& event);
[5876fcb]275
276    void OnMouseMove(wxMouseEvent& event) { m_Control->OnMouseMove(event); }
[887c26e]277    void OnLeaveWindow(wxMouseEvent& event);
278
[ea2485e]279    void OnLButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnLButtonDown(event); }
[5876fcb]280    void OnLButtonUp(wxMouseEvent& event) { m_Control->OnLButtonUp(event); }
[ea2485e]281    void OnMButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnMButtonDown(event); }
[5876fcb]282    void OnMButtonUp(wxMouseEvent& event) { m_Control->OnMButtonUp(event); }
[ea2485e]283    void OnRButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnRButtonDown(event); }
[5876fcb]284    void OnRButtonUp(wxMouseEvent& event) { m_Control->OnRButtonUp(event); }
[ea2485e]285    void OnMouseWheel(wxMouseEvent& event) { SetFocus(); m_Control->OnMouseWheel(event); }
[5876fcb]286    void OnKeyPress(wxKeyEvent &event) { m_Control->OnKeyPress(event); }
287
[1690fa9]288    bool Animate();
[2a3d328]289    bool Animating() const {
290        return m_Rotating || m_SwitchingTo || presentation_mode != 0;
291    }
[84cab34]292
[d877aa2]293    void ClearCoords();
[5876fcb]294    void SetCoords(wxPoint);
295
[2a3d328]296    // Determine whether the compass is currently shown.
297    bool ShowingCompass() const { return m_Compass; }
298    // Determine whether the clino is currently shown.
299    bool ShowingClino() const { return m_Clino; }
[9cf3688]300
[14acdae]301    bool PointWithinCompass(wxPoint point) const;
302    bool PointWithinClino(wxPoint point) const;
303    bool PointWithinScaleBar(wxPoint point) const;
[9cf3688]304
[5876fcb]305    void SetCompassFromPoint(wxPoint point);
306    void SetClinoFromPoint(wxPoint point);
307    void SetScaleBarFromOffset(wxCoord dx);
[9cf3688]308
[5876fcb]309    void RedrawIndicators();
[9cf3688]310
[5876fcb]311    void StartRotation();
312    void ToggleRotation();
313    void StopRotation();
[eef68f9]314    bool IsExtendedElevation() const;
[5876fcb]315    void ReverseRotation();
316    void RotateSlower(bool accel);
317    void RotateFaster(bool accel);
[9cf3688]318
[5876fcb]319    void SwitchToElevation();
320    void SwitchToPlan();
[9cf3688]321
[d1628e8e]322    void SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax);
323
[14acdae]324    bool ShowingPlan() const;
325    bool ShowingElevation() const;
326    bool ShowingMeasuringLine() const;
[570d62c3]327    bool HereIsReal() const { return m_here.IsValid() && !m_here_is_temporary; }
[5876fcb]328
[14acdae]329    bool CanRaiseViewpoint() const;
330    bool CanLowerViewpoint() const;
[5876fcb]331
[82f584f]332    bool IsRotating() const { return m_Rotating; }
[b61b020]333    bool HasData() const { return m_DoneFirstShow && m_HaveData; }
[78c67a6]334    bool HasDepth() const;
[d4650b3]335    bool HasRangeOfDates() const;
[c61aa79]336    bool HasErrorInformation() const;
[5876fcb]337
[5b7164d]338    double GetScale() const { return m_Scale; }
[5876fcb]339    void SetScale(Double scale);
[9cf3688]340
[82f584f]341    bool ShowingStationNames() const { return m_Names; }
342    bool ShowingOverlappingNames() const { return m_OverlappingNames; }
343    bool ShowingCrosses() const { return m_Crosses; }
[0580c6a]344    bool ShowingGrid() const { return m_Grid; }
[5876fcb]345
[d4650b3]346    int ColouringBy() const { return m_ColourBy; }
[da6c802]347
[f433fda]348    bool HasUndergroundLegs() const;
349    bool HasSurfaceLegs() const;
[50e8979]350    bool HasTubes() const;
[5876fcb]351
[82f584f]352    bool ShowingUndergroundLegs() const { return m_Legs; }
353    bool ShowingSurfaceLegs() const { return m_Surface; }
[5876fcb]354
[82f584f]355    bool ShowingDepthBar() const { return m_Depthbar; }
356    bool ShowingScaleBar() const { return m_Scalebar; }
[5876fcb]357
[82f584f]358    bool ShowingEntrances() const { return m_Entrances; }
359    bool ShowingFixedPts() const { return m_FixedPts; }
360    bool ShowingExportedPts() const { return m_ExportedPts; }
[5876fcb]361
[14acdae]362    int GetNumEntrances() const;
363    int GetNumFixedPts() const;
364    int GetNumExportedPts() const;
[5876fcb]365
[ef1870d]366    void ToggleUndergroundLegs() {
367        ToggleFlag(&m_Legs, UPDATE_BLOBS_AND_CROSSES);
368    }
369    void ToggleSurfaceLegs() {
370        ToggleFlag(&m_Surface, UPDATE_BLOBS_AND_CROSSES);
371    }
[6747314]372    void ToggleCompass() { ToggleFlag(&m_Compass); }
373    void ToggleClino() { ToggleFlag(&m_Clino); }
374    void ToggleScaleBar() { ToggleFlag(&m_Scalebar); }
[eff44b9]375    void ToggleEntrances() { ToggleFlag(&m_Entrances, UPDATE_BLOBS); }
376    void ToggleFixedPts() { ToggleFlag(&m_FixedPts, UPDATE_BLOBS); }
377    void ToggleExportedPts() { ToggleFlag(&m_ExportedPts, UPDATE_BLOBS); }
[5876fcb]378    void ToggleGrid() { ToggleFlag(&m_Grid); }
[2a3d328]379    void ToggleCrosses() { ToggleFlag(&m_Crosses); }
[eff44b9]380    void ToggleStationNames() { ToggleFlag(&m_Names); }
[5876fcb]381    void ToggleOverlappingNames() { ToggleFlag(&m_OverlappingNames); }
[6747314]382    void ToggleDepthBar() { ToggleFlag(&m_Depthbar); }
[3515947]383    void ToggleMetric() { ToggleFlag(&m_Metric); InvalidateList(LIST_DEPTHBAR); }
[6747314]384    void ToggleDegrees() { ToggleFlag(&m_Degrees); }
[eff44b9]385    void ToggleTubes() { ToggleFlag(&m_Tubes); }
[6747314]386    void TogglePerspective() { GLACanvas::TogglePerspective(); ForceRefresh(); }
[d67450e]387    void ToggleSmoothShading();
[f4c5932]388    bool DisplayingBoundingBox() const { return m_BoundingBox; }
389    void ToggleBoundingBox() { ToggleFlag(&m_BoundingBox); }
[5876fcb]390
[82f584f]391    bool GetMetric() const { return m_Metric; }
392    bool GetDegrees() const { return m_Degrees; }
393    bool GetTubes() const { return m_Tubes; }
[9cf3688]394
[2072157]395    bool CheckHitTestGrid(const wxPoint& point, bool centre);
[5876fcb]396
397    void ClearTreeSelection();
398
399    void Defaults();
[5757725]400
[b13aee4]401    void FullScreenMode();
402
[fdfa926]403    bool IsFullScreen() const;
404
[33b2094]405    void DragFinished();
406
[b5d64e6]407    void SplitLineAcrossBands(int band, int band2,
[4a0e6b35]408                              const Vector3 &p, const Vector3 &q,
[9eb58d0]409                              Double factor = 1.0);
[14acdae]410    int GetDepthColour(Double z) const;
411    Double GetDepthBoundaryBetweenBands(int a, int b) const;
[c61aa79]412    void AddPolyline(const traverse & centreline);
413    void AddPolylineDepth(const traverse & centreline);
414    void AddPolylineDate(const traverse & centreline);
415    void AddPolylineError(const traverse & centreline);
[9cf3688]416    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
[82f584f]417                          const Vector3 &c, const Vector3 &d);
[c61aa79]418    void AddPolylineShadow(const traverse & centreline);
[9cf3688]419    void AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b,
[da6c802]420                               const Vector3 &c, const Vector3 &d);
[d4650b3]421    void AddQuadrilateralDate(const Vector3 &a, const Vector3 &b,
422                              const Vector3 &c, const Vector3 &d);
[c61aa79]423    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
424                               const Vector3 &c, const Vector3 &d);
[46361bc]425    void MoveViewer(double forward, double up, double right);
[1690fa9]426
[da6c802]427    void (GfxCore::* AddQuad)(const Vector3 &a, const Vector3 &b,
428                              const Vector3 &c, const Vector3 &d);
[c61aa79]429    void (GfxCore::* AddPoly)(const traverse & centreline);
[da6c802]430
[1690fa9]431    PresentationMark GetView() const;
432    void SetView(const PresentationMark & p);
[128fac4]433    void PlayPres(double speed, bool change_speed = true);
434    int GetPresentationMode() const { return presentation_mode; }
[762c324]435    double GetPresentationSpeed() const { return presentation_mode ? pres_speed : 0; }
[1690fa9]436
[da6c802]437    void SetColourBy(int colour_by);
[6a4cdcb6]438    bool ExportMovie(const wxString & fnm);
[ce403f1]439    void OnPrint(const wxString &filename, const wxString &title,
440                 const wxString &datestamp);
[5940815]441    void OnExport(const wxString &filename, const wxString &title);
[e2c1671]442    void SetCursor(GfxCore::cursor new_cursor);
[6a4cdcb6]443
[5809313]444private:
[84cab34]445    DECLARE_EVENT_TABLE()
[5809313]446};
447
448#endif
Note: See TracBrowser for help on using the repository browser.