source: git/src/gfxcore.h @ b38cd93

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

src/gfxcore.h: Work around Mac OS X polluting the global namespace
with a "Point" class.

git-svn-id: file:///home/survex-svn/survex/trunk@3475 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

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