source: git/src/gfxcore.h @ eaaa55b

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since eaaa55b was 08253d9, checked in by Olly Betts <olly@…>, 17 years ago

Just set the pan and tilt directly as OpenGL rotations rather than messing
around setting up and then decoding a quaternion. This fixes some glitches
when tilting while looking east, and eliminates 2 source files and 2 headers!

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