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

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
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
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 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
30#include "img.h"
31
32#include "guicontrol.h"
33#include "vector3.h"
34#include "wx.h"
35#include "gla.h"
36
37#include <list>
38#include <utility>
39#include <vector>
40
41using namespace std;
42
43class MainFrm;
44class traverse;
45
46extern const int NUM_DEPTH_COLOURS;
47
48class Point : public Vector3 {
49  public:
50    Point() {}
51    Point(const Vector3 & v) : Vector3(v) { }
52    Point(const img_point & pt) : Vector3(pt.x, pt.y, pt.z) { }
53    Double GetX() const { return x; }
54    Double GetY() const { return y; }
55    Double GetZ() const { return z; }
56    void Invalidate() { x = DBL_MAX; }
57    bool IsValid() const { return x != DBL_MAX; }
58};
59
60class XSect;
61class LabelInfo;
62class PointInfo;
63class MovieMaker;
64
65class PresentationMark : public Point {
66  public:
67    Double angle, tilt_angle;
68    Double scale;
69    Double time;
70    PresentationMark() : Point(), angle(0), tilt_angle(0), scale(0), time(0)
71        { }
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_)
76        { }
77    bool is_valid() const { return scale > 0; }
78};
79
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};
92
93class GfxCore : public GLACanvas {
94    Double m_Scale;
95    int m_ScaleBarWidth;
96
97    typedef enum {
98        LIST_COMPASS,
99        LIST_CLINO,
100        LIST_CLINO_BACK,
101        LIST_DEPTHBAR,
102        LIST_DATEBAR,
103        LIST_ERRORBAR,
104        LIST_UNDERGROUND_LEGS,
105        LIST_TUBES,
106        LIST_SURFACE_LEGS,
107        LIST_BLOBS,
108        LIST_CROSSES,
109        LIST_GRID,
110        LIST_SHADOW
111    } drawing_list;
112
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,
122        CURSOR_ZOOM,
123        CURSOR_ZOOM_ROTATE
124    } cursor;
125
126private:
127    GUIControl* m_Control;
128    char* m_LabelGrid;
129    MainFrm* m_Parent;
130    bool m_DoneFirstShow;
131    Double m_TiltAngle;
132    Double m_PanAngle;
133    bool m_Rotating;
134    Double m_RotationStep;
135    int m_SwitchingTo;
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;
143    bool m_Clino;
144    bool m_Tubes;
145    int m_XSize;
146    int m_YSize;
147    int m_ColourBy;
148
149    bool m_HaveData;
150    bool m_MouseOutsideCompass;
151    bool m_MouseOutsideElev;
152    bool m_Surface;
153    bool m_Entrances;
154    bool m_FixedPts;
155    bool m_ExportedPts;
156    bool m_Grid;
157    bool m_BoundingBox;
158
159    bool m_Degrees;
160    bool m_Metric;
161
162    list<LabelInfo*> *m_PointGrid;
163    bool m_HitTestGridValid;
164
165    bool m_here_is_temporary;
166    Point m_here, m_there;
167
168    wxStopWatch timer;
169    long drawtime;
170
171    GLAPen * m_Pens;
172
173#define PLAYING 1
174    int presentation_mode; // for now, 0 => off, PLAYING => continuous play
175    bool pres_reverse;
176    double pres_speed;
177    PresentationMark next_mark;
178    double next_mark_time;
179    double this_mark_total;
180
181    MovieMaker * mpeg;
182
183    cursor current_cursor;
184
185    void PlaceVertexWithColour(const Vector3 &v, Double factor = 1.0);
186    void PlaceVertexWithDepthColour(const Vector3 & v, Double factor = 1.0);
187
188    void SetColourFromDate(time_t date, Double factor);
189    void SetColourFromError(double E, Double factor);
190
191    int GetClinoOffset() const;
192    void DrawTick(int angle_cw);
193    void DrawArrow(gla_colour col1, gla_colour col2);
194    wxString FormatLength(Double, bool scalebar = true);
195
196    void SkinPassage(const vector<XSect> & centreline);
197
198    virtual void GenerateList(unsigned int l);
199    void GenerateDisplayList();
200    void GenerateDisplayListTubes();
201    void GenerateDisplayListSurface();
202    void GenerateDisplayListShadow();
203    void GenerateBlobsDisplayList();
204
205    void DrawIndicators();
206
207    void TryToFreeArrays();
208    void FirstShow();
209
210    void DrawScalebar();
211    void DrawDepthbar();
212    void DrawDatebar();
213    void DrawErrorbar();
214    void DrawCompass();
215    void DrawClino();
216    void DrawClinoBack();
217    void Draw2dIndicators();
218    void DrawGrid();
219
220    void NattyDrawNames();
221    void SimpleDrawNames();
222
223    void DefaultParameters();
224
225    void Repaint();
226
227    void CreateHitTestGrid();
228
229    int GetCompassXPosition() const;
230    int GetClinoXPosition() const;
231    int GetIndicatorYPosition() const;
232    int GetIndicatorRadius() const;
233
234    void ToggleFlag(bool* flag, int update = UPDATE_NONE);
235
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
245    void DrawShadowedBoundingBox();
246    void DrawBoundingBox();
247
248public:
249    GfxCore(MainFrm* parent, wxWindow* parent_window, GUIControl* control);
250    ~GfxCore();
251
252    void Initialise(bool same_file);
253    void InitialiseTerrain();
254
255    void UpdateBlobs();
256    void ForceRefresh();
257
258    void RefreshLine(const Point& a, const Point& b, const Point& c);
259
260    void SetHere();
261    void SetHere(const Point &p);
262    void SetThere();
263    void SetThere(const Point &p);
264
265    void CentreOn(const Point &p);
266
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);
274    void OnIdle(wxIdleEvent& event);
275
276    void OnMouseMove(wxMouseEvent& event) { m_Control->OnMouseMove(event); }
277    void OnLeaveWindow(wxMouseEvent& event);
278
279    void OnLButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnLButtonDown(event); }
280    void OnLButtonUp(wxMouseEvent& event) { m_Control->OnLButtonUp(event); }
281    void OnMButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnMButtonDown(event); }
282    void OnMButtonUp(wxMouseEvent& event) { m_Control->OnMButtonUp(event); }
283    void OnRButtonDown(wxMouseEvent& event) { SetFocus(); m_Control->OnRButtonDown(event); }
284    void OnRButtonUp(wxMouseEvent& event) { m_Control->OnRButtonUp(event); }
285    void OnMouseWheel(wxMouseEvent& event) { SetFocus(); m_Control->OnMouseWheel(event); }
286    void OnKeyPress(wxKeyEvent &event) { m_Control->OnKeyPress(event); }
287
288    bool Animate();
289    bool Animating() const {
290        return m_Rotating || m_SwitchingTo || presentation_mode != 0;
291    }
292
293    void ClearCoords();
294    void SetCoords(wxPoint);
295
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; }
300
301    bool PointWithinCompass(wxPoint point) const;
302    bool PointWithinClino(wxPoint point) const;
303    bool PointWithinScaleBar(wxPoint point) const;
304
305    void SetCompassFromPoint(wxPoint point);
306    void SetClinoFromPoint(wxPoint point);
307    void SetScaleBarFromOffset(wxCoord dx);
308
309    void RedrawIndicators();
310
311    void StartRotation();
312    void ToggleRotation();
313    void StopRotation();
314    bool IsExtendedElevation() const;
315    void ReverseRotation();
316    void RotateSlower(bool accel);
317    void RotateFaster(bool accel);
318
319    void SwitchToElevation();
320    void SwitchToPlan();
321
322    void SetViewTo(Double xmin, Double xmax, Double ymin, Double ymax, Double zmin, Double zmax);
323
324    bool ShowingPlan() const;
325    bool ShowingElevation() const;
326    bool ShowingMeasuringLine() const;
327    bool HereIsReal() const { return m_here.IsValid() && !m_here_is_temporary; }
328
329    bool CanRaiseViewpoint() const;
330    bool CanLowerViewpoint() const;
331
332    bool IsRotating() const { return m_Rotating; }
333    bool HasData() const { return m_DoneFirstShow && m_HaveData; }
334    bool HasDepth() const;
335    bool HasRangeOfDates() const;
336    bool HasErrorInformation() const;
337
338    double GetScale() const { return m_Scale; }
339    void SetScale(Double scale);
340
341    bool ShowingStationNames() const { return m_Names; }
342    bool ShowingOverlappingNames() const { return m_OverlappingNames; }
343    bool ShowingCrosses() const { return m_Crosses; }
344    bool ShowingGrid() const { return m_Grid; }
345
346    int ColouringBy() const { return m_ColourBy; }
347
348    bool HasUndergroundLegs() const;
349    bool HasSurfaceLegs() const;
350    bool HasTubes() const;
351
352    bool ShowingUndergroundLegs() const { return m_Legs; }
353    bool ShowingSurfaceLegs() const { return m_Surface; }
354
355    bool ShowingDepthBar() const { return m_Depthbar; }
356    bool ShowingScaleBar() const { return m_Scalebar; }
357
358    bool ShowingEntrances() const { return m_Entrances; }
359    bool ShowingFixedPts() const { return m_FixedPts; }
360    bool ShowingExportedPts() const { return m_ExportedPts; }
361
362    int GetNumEntrances() const;
363    int GetNumFixedPts() const;
364    int GetNumExportedPts() const;
365
366    void ToggleUndergroundLegs() {
367        ToggleFlag(&m_Legs, UPDATE_BLOBS_AND_CROSSES);
368    }
369    void ToggleSurfaceLegs() {
370        ToggleFlag(&m_Surface, UPDATE_BLOBS_AND_CROSSES);
371    }
372    void ToggleCompass() { ToggleFlag(&m_Compass); }
373    void ToggleClino() { ToggleFlag(&m_Clino); }
374    void ToggleScaleBar() { ToggleFlag(&m_Scalebar); }
375    void ToggleEntrances() { ToggleFlag(&m_Entrances, UPDATE_BLOBS); }
376    void ToggleFixedPts() { ToggleFlag(&m_FixedPts, UPDATE_BLOBS); }
377    void ToggleExportedPts() { ToggleFlag(&m_ExportedPts, UPDATE_BLOBS); }
378    void ToggleGrid() { ToggleFlag(&m_Grid); }
379    void ToggleCrosses() { ToggleFlag(&m_Crosses); }
380    void ToggleStationNames() { ToggleFlag(&m_Names); }
381    void ToggleOverlappingNames() { ToggleFlag(&m_OverlappingNames); }
382    void ToggleDepthBar() { ToggleFlag(&m_Depthbar); }
383    void ToggleMetric() { ToggleFlag(&m_Metric); InvalidateList(LIST_DEPTHBAR); }
384    void ToggleDegrees() { ToggleFlag(&m_Degrees); }
385    void ToggleTubes() { ToggleFlag(&m_Tubes); }
386    void TogglePerspective() { GLACanvas::TogglePerspective(); ForceRefresh(); }
387    void ToggleSmoothShading();
388    bool DisplayingBoundingBox() const { return m_BoundingBox; }
389    void ToggleBoundingBox() { ToggleFlag(&m_BoundingBox); }
390
391    bool GetMetric() const { return m_Metric; }
392    bool GetDegrees() const { return m_Degrees; }
393    bool GetTubes() const { return m_Tubes; }
394
395    bool CheckHitTestGrid(const wxPoint& point, bool centre);
396
397    void ClearTreeSelection();
398
399    void Defaults();
400
401    void FullScreenMode();
402
403    bool IsFullScreen() const;
404
405    void DragFinished();
406
407    void SplitLineAcrossBands(int band, int band2,
408                              const Vector3 &p, const Vector3 &q,
409                              Double factor = 1.0);
410    int GetDepthColour(Double z) const;
411    Double GetDepthBoundaryBetweenBands(int a, int b) const;
412    void AddPolyline(const traverse & centreline);
413    void AddPolylineDepth(const traverse & centreline);
414    void AddPolylineDate(const traverse & centreline);
415    void AddPolylineError(const traverse & centreline);
416    void AddQuadrilateral(const Vector3 &a, const Vector3 &b,
417                          const Vector3 &c, const Vector3 &d);
418    void AddPolylineShadow(const traverse & centreline);
419    void AddQuadrilateralDepth(const Vector3 &a, const Vector3 &b,
420                               const Vector3 &c, const Vector3 &d);
421    void AddQuadrilateralDate(const Vector3 &a, const Vector3 &b,
422                              const Vector3 &c, const Vector3 &d);
423    void AddQuadrilateralError(const Vector3 &a, const Vector3 &b,
424                               const Vector3 &c, const Vector3 &d);
425    void MoveViewer(double forward, double up, double right);
426
427    void (GfxCore::* AddQuad)(const Vector3 &a, const Vector3 &b,
428                              const Vector3 &c, const Vector3 &d);
429    void (GfxCore::* AddPoly)(const traverse & centreline);
430
431    PresentationMark GetView() const;
432    void SetView(const PresentationMark & p);
433    void PlayPres(double speed, bool change_speed = true);
434    int GetPresentationMode() const { return presentation_mode; }
435    double GetPresentationSpeed() const { return presentation_mode ? pres_speed : 0; }
436
437    void SetColourBy(int colour_by);
438    bool ExportMovie(const wxString & fnm);
439    void OnPrint(const wxString &filename, const wxString &title,
440                 const wxString &datestamp);
441    void OnExport(const wxString &filename, const wxString &title);
442    void SetCursor(GfxCore::cursor new_cursor);
443
444private:
445    DECLARE_EVENT_TABLE()
446};
447
448#endif
Note: See TracBrowser for help on using the repository browser.