source: git/src/gfxcore.h @ 0784240

RELEASE/1.0
Last change on this file since 0784240 was 0784240, checked in by Olly Betts <olly@…>, 13 years ago

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

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3710 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 11.2 KB
Line 
1//
2//  gfxcore.h
3//
4//  Core drawing code for Aven.
5//
6//  Copyright (C) 2000-2001, Mark R. Shinwell.
7//  Copyright (C) 2001-2002,2004,2005 Olly Betts
8//
9//  This program is free software; you can redistribute it and/or modify
10//  it under the terms of the GNU General Public License as published by
11//  the Free Software Foundation; either version 2 of the License, or
12//  (at your option) any later version.
13//
14//  This program is distributed in the hope that it will be useful,
15//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17//  GNU General Public License for more details.
18//
19//  You should have received a copy of the GNU General Public License
20//  along with this program; if not, write to the Free Software
21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
22//
23
24#ifndef gfxcore_h
25#define gfxcore_h
26
27#include <float.h>
28
29#include "quaternion.h"
30#include "wx.h"
31#include <utility>
32#include <list>
33
34using std::list;
35
36class MainFrm;
37class PointInfo;
38
39struct ColourTriple {
40    // RGB triple: values are from 0-255 inclusive for each component.
41    int r;
42    int g;
43    int b;
44};
45
46// Colours for drawing.
47// These must be in the same order as the entries in COLOURS[] in gfxcore.cc.
48enum AvenColour {
49    col_BLACK = 0,
50    col_GREY,
51    col_LIGHT_GREY,
52    col_LIGHT_GREY_2,
53    col_DARK_GREY,
54    col_WHITE,
55    col_TURQUOISE,
56    col_GREEN,
57    col_INDICATOR_1,
58    col_INDICATOR_2,
59    col_YELLOW,
60    col_RED,
61    col_LAST // must be the last entry here
62};
63
64// Mac OS X headers pollute the global namespace with generic names like
65// "class Point", which clashes with our "class Point".  So for __WXMAC__
66// put our class in a namespace and define Point as a macro.
67#ifdef __WXMAC__
68namespace svx {
69#endif
70
71class Point {
72    friend class GfxCore;
73    Double x, y, z;
74public:
75    Point() {}
76    Point(Double x_, Double y_, Double z_) : x(x_), y(y_), z(z_) {}
77};
78
79#ifdef __WXMAC__
80}
81#define Point svx::Point
82#endif
83
84class LabelInfo;
85
86extern const ColourTriple COLOURS[]; // defined in gfxcore.cc
87
88class GfxCore : public wxWindow {
89    struct params {
90        Quaternion rotation;
91        Double scale;
92        struct {
93            Double x;
94            Double y;
95            Double z;
96        } translation;
97    } m_Params;
98
99    enum LockFlags {
100        lock_NONE = 0,
101        lock_X = 1,
102        lock_Y = 2,
103        lock_Z = 4,
104        lock_POINT = lock_X | lock_Y | lock_Z,
105        lock_XZ = lock_X | lock_Z,
106        lock_YZ = lock_Y | lock_Z,
107        lock_XY = lock_X | lock_Y
108    };
109
110    struct PlotData {
111        Point *vertices;
112        Point *surface_vertices;
113        int* num_segs;
114        int* surface_num_segs;
115    };
116
117    struct {
118        int offset_x;
119        int offset_y;
120        int width;
121        int drag_start_offset_x;
122        int drag_start_offset_y;
123    } m_ScaleBar;
124
125    double m_MaxExtent; // twice the maximum of the {x,y,z}-extents, in survey coordinates.
126    char *m_LabelGrid;
127    bool m_RotationOK;
128    LockFlags m_Lock;
129    Matrix4 m_RotationMatrix;
130    bool m_DraggingLeft;
131    bool m_DraggingMiddle;
132    bool m_DraggingRight;
133    MainFrm* m_Parent;
134    wxPoint m_DragStart;
135    wxPoint m_DragRealStart;
136    wxPoint m_DragLast;
137    wxBitmap* m_OffscreenBitmap;
138    wxMemoryDC m_DrawDC;
139    bool m_DoneFirstShow;
140    bool m_RedrawOffscreen;
141    int* m_Polylines;
142    int* m_SurfacePolylines;
143    int m_Bands;
144    Double m_InitialScale;
145    Double m_TiltAngle;
146    Double m_PanAngle;
147    bool m_Rotating;
148    Double m_RotationStep;
149    int m_SwitchingTo;
150    bool m_ReverseControls;
151    bool m_Crosses;
152    bool m_Legs;
153    bool m_Names;
154    bool m_Scalebar;
155    wxFont m_Font;
156    bool m_Depthbar;
157    bool m_OverlappingNames;
158    bool m_Compass;
159    bool m_Clino;
160    int m_XSize;
161    int m_YSize;
162    int m_XCentre;
163    int m_YCentre;
164    PlotData* m_PlotData;
165    bool m_InitialisePending;
166    enum { drag_NONE, drag_MAIN, drag_COMPASS, drag_ELEV, drag_SCALE } m_LastDrag;
167    bool m_MouseOutsideCompass;
168    bool m_MouseOutsideElev;
169    bool m_UndergroundLegs;
170    bool m_SurfaceLegs;
171    bool m_Surface;
172    bool m_SurfaceDashed;
173    bool m_SurfaceDepth;
174    bool m_Entrances;
175    bool m_FixedPts;
176    bool m_ExportedPts;
177    bool m_Grid;
178
179    list<LabelInfo*> *m_PointGrid;
180    bool m_HitTestGridValid;
181
182    Point m_here, m_there;
183
184    wxStopWatch timer;
185    long drawtime;
186   
187    bool clipping;
188
189    wxPen* m_Pens;
190    wxBrush* m_Brushes;
191
192    void SetColour(AvenColour col, bool background = false /* true => foreground */) {
193        assert(col >= (AvenColour) 0 && col < col_LAST);
194        if (background) {
195            assert(m_Brushes[col].Ok());
196            m_DrawDC.SetBrush(m_Brushes[col]);
197        }
198        else {
199            assert(m_Pens[col].Ok());
200            m_DrawDC.SetPen(m_Pens[col]);
201        }
202    }
203
204    Double XToScreen(Double x, Double y, Double z) {
205        return Double(x * m_RotationMatrix.get(0, 0) +
206                      y * m_RotationMatrix.get(0, 1) +
207                      z * m_RotationMatrix.get(0, 2));
208    }
209
210    Double YToScreen(Double x, Double y, Double z) {
211        return Double(x * m_RotationMatrix.get(1, 0) +
212                      y * m_RotationMatrix.get(1, 1) +
213                      z * m_RotationMatrix.get(1, 2));
214    }
215
216    Double ZToScreen(Double x, Double y, Double z) {
217        return Double(x * m_RotationMatrix.get(2, 0) +
218                      y * m_RotationMatrix.get(2, 1) +
219                      z * m_RotationMatrix.get(2, 2));
220    }
221
222    Double GridXToScreen(Double x, Double y, Double z);
223    Double GridYToScreen(Double x, Double y, Double z);
224    Double GridXToScreen(const Point &p) {
225        return GridXToScreen(p.x, p.y, p.z);
226    }
227    Double GridYToScreen(const Point &p) {
228        return GridYToScreen(p.x, p.y, p.z);
229    }
230
231    void CheckHitTestGrid(wxPoint& point, bool centre);
232
233    wxCoord GetClinoOffset();
234    wxPoint CompassPtToScreen(Double x, Double y, Double z);
235    void DrawTick(wxCoord cx, wxCoord cy, int angle_cw);
236    wxString FormatLength(Double, bool scalebar = true);
237
238    void SetScale(Double scale);
239    void SetScaleInitial(Double scale);
240    void DrawBand(int num_polylines, const int *num_segs, const Point *vertices,
241                  Double m_00, Double m_01, Double m_02,
242                  Double m_20, Double m_21, Double m_22);
243    void RedrawOffscreen();
244    void TryToFreeArrays();
245    void FirstShow();
246
247    void DrawScalebar();
248    void DrawDepthbar();
249    void Draw2dIndicators();
250    void DrawGrid();
251
252    wxPoint IndicatorCompassToScreenPan(int angle);
253    wxPoint IndicatorCompassToScreenElev(int angle);
254
255    void HandleScaleRotate(bool, wxPoint);
256    void HandleTilt(wxPoint);
257    void HandleTranslate(wxPoint);
258
259    void TranslateCave(int dx, int dy);
260    void TiltCave(Double tilt_angle);
261    void TurnCave(Double angle);
262    void TurnCaveTo(Double angle);
263
264    void DrawNames();
265    void NattyDrawNames();
266    void SimpleDrawNames();
267
268    void Repaint();
269
270    void CreateHitTestGrid();
271
272public:
273    bool m_Degrees;
274    bool m_Metric;
275
276    GfxCore(MainFrm* parent, wxWindow* parent_window);
277    ~GfxCore();
278
279    void Initialise();
280    void InitialiseOnNextResize() { m_InitialisePending = true; }
281    void InitialiseTerrain();
282
283    void ForceRefresh();
284
285    void RefreshLine(const Point &a, const Point &b, const Point &c);
286 
287    void SetHere();
288    void SetHere(Double x, Double y, Double z);
289    void SetThere();
290    void SetThere(Double x, Double y, Double z);
291
292    void CentreOn(Double x, Double y, Double z);
293
294    void OnDefaults();
295    void OnPlan();
296    void OnElevation();
297    void OnDisplayOverlappingNames();
298    void OnShowCrosses();
299    void OnShowStationNames();
300    void OnShowSurveyLegs();
301    void OnShowSurface();
302    void OnShowSurfaceDepth();
303    void OnShowSurfaceDashed();
304    void OnMoveEast();
305    void OnMoveNorth();
306    void OnMoveSouth();
307    void OnMoveWest();
308    void OnStartRotation();
309    void OnToggleRotation();
310    void OnStopRotation();
311    void OnReverseControls();
312    void OnSlowDown(bool accel = false);
313    void OnSpeedUp(bool accel = false);
314    void OnStepOnceAnticlockwise(bool accel = false);
315    void OnStepOnceClockwise(bool accel = false);
316    void OnHigherViewpoint(bool accel = false);
317    void OnLowerViewpoint(bool accel = false);
318    void OnShiftDisplayDown(bool accel = false);
319    void OnShiftDisplayLeft(bool accel = false);
320    void OnShiftDisplayRight(bool accel = false);
321    void OnShiftDisplayUp(bool accel = false);
322    void OnZoomIn(bool accel = false);
323    void OnZoomOut(bool accel = false);
324    void OnToggleScalebar();
325    void OnToggleDepthbar();
326    void OnViewCompass();
327    void OnViewClino();
328    void OnViewGrid();
329    void OnReverseDirectionOfRotation();
330    void OnShowEntrances();
331    void OnShowFixedPts();
332    void OnShowExportedPts();
333    void OnCancelDistLine();
334
335    void OnPaint(wxPaintEvent&);
336    void OnSize(wxSizeEvent& event);
337    void OnIdle(wxIdleEvent& event);
338
339    void OnMouseMove(wxMouseEvent& event);
340    void OnLeaveWindow(wxMouseEvent& event);
341
342    void OnLButtonDown(wxMouseEvent& event);
343    void OnLButtonUp(wxMouseEvent& event);
344    void OnMButtonDown(wxMouseEvent& event);
345    void OnMButtonUp(wxMouseEvent& event);
346    void OnRButtonDown(wxMouseEvent& event);
347    void OnRButtonUp(wxMouseEvent& event);
348    bool Animate();
349
350    void OnKeyPress(wxKeyEvent &e);
351
352    void OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent&);
353    void OnShowCrossesUpdate(wxUpdateUIEvent&);
354    void OnShowStationNamesUpdate(wxUpdateUIEvent&);
355    void OnShowSurveyLegsUpdate(wxUpdateUIEvent&);
356    void OnShowSurfaceUpdate(wxUpdateUIEvent&);
357    void OnShowSurfaceDepthUpdate(wxUpdateUIEvent&);
358    void OnShowSurfaceDashedUpdate(wxUpdateUIEvent&);
359    void OnMoveEastUpdate(wxUpdateUIEvent&);
360    void OnMoveNorthUpdate(wxUpdateUIEvent&);
361    void OnMoveSouthUpdate(wxUpdateUIEvent&);
362    void OnMoveWestUpdate(wxUpdateUIEvent&);
363    void OnStartRotationUpdate(wxUpdateUIEvent&);
364    void OnToggleRotationUpdate(wxUpdateUIEvent&);
365    void OnStopRotationUpdate(wxUpdateUIEvent&);
366    void OnReverseControlsUpdate(wxUpdateUIEvent&);
367    void OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent&);
368    void OnSlowDownUpdate(wxUpdateUIEvent&);
369    void OnSpeedUpUpdate(wxUpdateUIEvent&);
370    void OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent&);
371    void OnStepOnceClockwiseUpdate(wxUpdateUIEvent&);
372    void OnDefaultsUpdate(wxUpdateUIEvent&);
373    void OnElevationUpdate(wxUpdateUIEvent&);
374    void OnHigherViewpointUpdate(wxUpdateUIEvent&);
375    void OnLowerViewpointUpdate(wxUpdateUIEvent&);
376    void OnPlanUpdate(wxUpdateUIEvent&);
377    void OnShiftDisplayDownUpdate(wxUpdateUIEvent&);
378    void OnShiftDisplayLeftUpdate(wxUpdateUIEvent&);
379    void OnShiftDisplayRightUpdate(wxUpdateUIEvent&);
380    void OnShiftDisplayUpUpdate(wxUpdateUIEvent&);
381    void OnZoomInUpdate(wxUpdateUIEvent&);
382    void OnZoomOutUpdate(wxUpdateUIEvent&);
383    void OnToggleScalebarUpdate(wxUpdateUIEvent&);
384    void OnToggleDepthbarUpdate(wxUpdateUIEvent&);
385    void OnViewCompassUpdate(wxUpdateUIEvent&);
386    void OnViewClinoUpdate(wxUpdateUIEvent&);
387    void OnViewGridUpdate(wxUpdateUIEvent&);
388    void OnShowEntrancesUpdate(wxUpdateUIEvent&);
389    void OnShowExportedPtsUpdate(wxUpdateUIEvent&);
390    void OnShowFixedPtsUpdate(wxUpdateUIEvent&);
391    void OnIndicatorsUpdate(wxUpdateUIEvent&);
392    void OnCancelDistLineUpdate(wxUpdateUIEvent&);
393
394    void OnToggleMetric();
395    void OnToggleMetricUpdate(wxUpdateUIEvent& cmd);
396       
397    void OnToggleDegrees();
398    void OnToggleDegreesUpdate(wxUpdateUIEvent& cmd);
399
400    void OnPrint(const wxString &filename, const wxString &title,
401                 const wxString &datestamp);
402    bool OnExport(const wxString &filename, const wxString &title);
403
404private:
405    DECLARE_EVENT_TABLE()
406};
407
408#endif
Note: See TracBrowser for help on using the repository browser.