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