source: git/src/gfxcore.h @ 1b71c05

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

src/: Update FSF address in (C) notices in source files.

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

  • Property mode set to 100644
File size: 10.9 KB
RevLine 
[5809313]1//
2//  gfxcore.h
3//
4//  Core drawing code for Aven.
5//
6//  Copyright (C) 2000-2001, Mark R. Shinwell.
[301bbc1]7//  Copyright (C) 2001-2002,2004,2005 Olly Betts
[5809313]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
[1b71c05]21//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
[5809313]22//
23
24#ifndef gfxcore_h
25#define gfxcore_h
26
[7aa15c0]27#include <float.h>
28
[5809313]29#include "quaternion.h"
30#include "wx.h"
[156dc16]31#include <utility>
32#include <list>
[5809313]33
[003d953]34using std::list;
35
[137bf99]36class MainFrm;
[e61185d]37class PointInfo;
[5809313]38
[156dc16]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.
[fa42426]47// These must be in the same order as the entries in COLOURS[] in gfxcore.cc.
[156dc16]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
[cd6ea75]64class Point {
[2a02de2]65    friend class GfxCore;
66    Double x, y, z;
[cd6ea75]67public:
68    Point() {}
69    Point(Double x_, Double y_, Double z_) : x(x_), y(y_), z(z_) {}
[2a02de2]70};
71
[39e460c9]72class LabelInfo;
73
[156dc16]74extern const ColourTriple COLOURS[]; // defined in gfxcore.cc
75
[5809313]76class GfxCore : public wxWindow {
77    struct params {
[421b7d2]78        Quaternion rotation;
79        Double scale;
80        struct {
[c6d95d8]81            Double x;
82            Double y;
83            Double z;
[5809313]84        } translation;
85    } m_Params;
86
[de7a879]87    enum LockFlags {
[421b7d2]88        lock_NONE = 0,
89        lock_X = 1,
[de7a879]90        lock_Y = 2,
91        lock_Z = 4,
92        lock_POINT = lock_X | lock_Y | lock_Z,
93        lock_XZ = lock_X | lock_Z,
94        lock_YZ = lock_Y | lock_Z,
95        lock_XY = lock_X | lock_Y
96    };
[5809313]97
98    struct PlotData {
[cd6ea75]99        Point *vertices;
100        Point *surface_vertices;
[421b7d2]101        int* num_segs;
102        int* surface_num_segs;
[5809313]103    };
104
[42adb19]105    struct {
[421b7d2]106        int offset_x;
107        int offset_y;
108        int width;
109        int drag_start_offset_x;
110        int drag_start_offset_y;
[42adb19]111    } m_ScaleBar;
112
[156dc16]113    double m_MaxExtent; // twice the maximum of the {x,y,z}-extents, in survey coordinates.
[d5de678]114    char *m_LabelGrid;
[303a525]115    bool m_RotationOK;
[de7a879]116    LockFlags m_Lock;
[5809313]117    Matrix4 m_RotationMatrix;
118    bool m_DraggingLeft;
119    bool m_DraggingMiddle;
120    bool m_DraggingRight;
[137bf99]121    MainFrm* m_Parent;
[5809313]122    wxPoint m_DragStart;
[2effbf1]123    wxPoint m_DragRealStart;
[26f3bd8]124    wxPoint m_DragLast;
[d8622e1]125    wxBitmap* m_OffscreenBitmap;
[5809313]126    wxMemoryDC m_DrawDC;
127    bool m_DoneFirstShow;
128    bool m_RedrawOffscreen;
129    int* m_Polylines;
[11a266e]130    int* m_SurfacePolylines;
[5809313]131    int m_Bands;
[c6d95d8]132    Double m_InitialScale;
133    Double m_TiltAngle;
134    Double m_PanAngle;
[5809313]135    bool m_Rotating;
[c6d95d8]136    Double m_RotationStep;
[3d00693]137    int m_SwitchingTo;
[5809313]138    bool m_ReverseControls;
139    bool m_Crosses;
140    bool m_Legs;
141    bool m_Names;
142    bool m_Scalebar;
[84cab34]143    wxFont m_Font;
[5809313]144    bool m_Depthbar;
145    bool m_OverlappingNames;
146    bool m_Compass;
[c300a04]147    bool m_Clino;
[5809313]148    int m_XSize;
149    int m_YSize;
150    int m_XCentre;
151    int m_YCentre;
152    PlotData* m_PlotData;
[068b4f2]153    bool m_InitialisePending;
[42adb19]154    enum { drag_NONE, drag_MAIN, drag_COMPASS, drag_ELEV, drag_SCALE } m_LastDrag;
[b56df45]155    bool m_MouseOutsideCompass;
156    bool m_MouseOutsideElev;
[e8bc148]157    bool m_UndergroundLegs;
158    bool m_SurfaceLegs;
159    bool m_Surface;
160    bool m_SurfaceDashed;
161    bool m_SurfaceDepth;
[fe444b8]162    bool m_Entrances;
163    bool m_FixedPts;
164    bool m_ExportedPts;
[c1cf79d]165    bool m_Grid;
[fa42426]166
167    list<LabelInfo*> *m_PointGrid;
[dfe4454c]168    bool m_HitTestGridValid;
[5809313]169
[ef07952]170    Point m_here, m_there;
[156dc16]171
[a8e9fde]172    wxStopWatch timer;
173    long drawtime;
[b6de07d]174   
175    bool clipping;
[a8e9fde]176
[156dc16]177    wxPen* m_Pens;
178    wxBrush* m_Brushes;
179
180    void SetColour(AvenColour col, bool background = false /* true => foreground */) {
[421b7d2]181        assert(col >= (AvenColour) 0 && col < col_LAST);
[156dc16]182        if (background) {
183            assert(m_Brushes[col].Ok());
[421b7d2]184            m_DrawDC.SetBrush(m_Brushes[col]);
[156dc16]185        }
186        else {
187            assert(m_Pens[col].Ok());
188            m_DrawDC.SetPen(m_Pens[col]);
189        }
190    }
191
[c6d95d8]192    Double XToScreen(Double x, Double y, Double z) {
[421b7d2]193        return Double(x * m_RotationMatrix.get(0, 0) +
[003d953]194                      y * m_RotationMatrix.get(0, 1) +
195                      z * m_RotationMatrix.get(0, 2));
[5809313]196    }
197
[c6d95d8]198    Double YToScreen(Double x, Double y, Double z) {
[421b7d2]199        return Double(x * m_RotationMatrix.get(1, 0) +
[003d953]200                      y * m_RotationMatrix.get(1, 1) +
201                      z * m_RotationMatrix.get(1, 2));
[5809313]202    }
203
[c6d95d8]204    Double ZToScreen(Double x, Double y, Double z) {
[421b7d2]205        return Double(x * m_RotationMatrix.get(2, 0) +
[003d953]206                      y * m_RotationMatrix.get(2, 1) +
207                      z * m_RotationMatrix.get(2, 2));
[5809313]208    }
[168df28]209
[c6d95d8]210    Double GridXToScreen(Double x, Double y, Double z);
211    Double GridYToScreen(Double x, Double y, Double z);
[2173dbd]212    Double GridXToScreen(const Point &p) {
213        return GridXToScreen(p.x, p.y, p.z);
214    }
215    Double GridYToScreen(const Point &p) {
216        return GridYToScreen(p.x, p.y, p.z);
217    }
[c1cf79d]218
[2effbf1]219    void CheckHitTestGrid(wxPoint& point, bool centre);
220
[c300a04]221    wxCoord GetClinoOffset();
[c6d95d8]222    wxPoint CompassPtToScreen(Double x, Double y, Double z);
[b56df45]223    void DrawTick(wxCoord cx, wxCoord cy, int angle_cw);
[c6d95d8]224    wxString FormatLength(Double, bool scalebar = true);
[5809313]225
[cd6ea75]226    void SetScale(Double scale);
227    void SetScaleInitial(Double scale);
[b6de07d]228    void DrawBand(int num_polylines, const int *num_segs, const Point *vertices,
229                  Double m_00, Double m_01, Double m_02,
230                  Double m_20, Double m_21, Double m_22);
[5809313]231    void RedrawOffscreen();
232    void TryToFreeArrays();
233    void FirstShow();
[84cab34]234
235    void DrawScalebar();
236    void DrawDepthbar();
[6606406]237    void Draw2dIndicators();
[c1cf79d]238    void DrawGrid();
[6606406]239
240    wxPoint IndicatorCompassToScreenPan(int angle);
241    wxPoint IndicatorCompassToScreenElev(int angle);
[5809313]242
243    void HandleScaleRotate(bool, wxPoint);
244    void HandleTilt(wxPoint);
245    void HandleTranslate(wxPoint);
246
[c8c116c]247    void TranslateCave(int dx, int dy);
[c6d95d8]248    void TiltCave(Double tilt_angle);
249    void TurnCave(Double angle);
250    void TurnCaveTo(Double angle);
[f626e1f]251
[84cab34]252    void DrawNames();
253    void NattyDrawNames();
254    void SimpleDrawNames();
255
[0e864da5]256    void Repaint();
257
[dfe4454c]258    void CreateHitTestGrid();
[421b7d2]259
[5809313]260public:
[7a89dc2]261    bool m_Degrees;
262    bool m_Metric;
263
[156dc16]264    GfxCore(MainFrm* parent, wxWindow* parent_window);
[5809313]265    ~GfxCore();
266
267    void Initialise();
[137bf99]268    void InitialiseOnNextResize() { m_InitialisePending = true; }
[8000d8f]269    void InitialiseTerrain();
[a87b1f7]270
[fa42426]271    void ForceRefresh();
[156dc16]272
[6009a17]273    void RefreshLine(const Point &a, const Point &b, const Point &c);
[2173dbd]274 
[fd6e0d5]275    void SetHere();
276    void SetHere(Double x, Double y, Double z);
277    void SetThere();
278    void SetThere(Double x, Double y, Double z);
279
[156dc16]280    void CentreOn(Double x, Double y, Double z);
281
[4b1fc48]282    void OnDefaults();
283    void OnPlan();
284    void OnElevation();
285    void OnDisplayOverlappingNames();
286    void OnShowCrosses();
287    void OnShowStationNames();
288    void OnShowSurveyLegs();
289    void OnShowSurface();
290    void OnShowSurfaceDepth();
291    void OnShowSurfaceDashed();
292    void OnMoveEast();
293    void OnMoveNorth();
294    void OnMoveSouth();
295    void OnMoveWest();
296    void OnStartRotation();
297    void OnToggleRotation();
298    void OnStopRotation();
299    void OnReverseControls();
[ba2c5b1]300    void OnSlowDown(bool accel = false);
301    void OnSpeedUp(bool accel = false);
302    void OnStepOnceAnticlockwise(bool accel = false);
303    void OnStepOnceClockwise(bool accel = false);
304    void OnHigherViewpoint(bool accel = false);
305    void OnLowerViewpoint(bool accel = false);
306    void OnShiftDisplayDown(bool accel = false);
307    void OnShiftDisplayLeft(bool accel = false);
308    void OnShiftDisplayRight(bool accel = false);
309    void OnShiftDisplayUp(bool accel = false);
310    void OnZoomIn(bool accel = false);
311    void OnZoomOut(bool accel = false);
[4b1fc48]312    void OnToggleScalebar();
313    void OnToggleDepthbar();
314    void OnViewCompass();
315    void OnViewClino();
316    void OnViewGrid();
317    void OnReverseDirectionOfRotation();
318    void OnShowEntrances();
319    void OnShowFixedPts();
320    void OnShowExportedPts();
[6d109e5]321    void OnCancelDistLine();
[84cab34]322
[5809313]323    void OnPaint(wxPaintEvent&);
[168df28]324    void OnSize(wxSizeEvent& event);
325    void OnIdle(wxIdleEvent& event);
326
[5809313]327    void OnMouseMove(wxMouseEvent& event);
[168df28]328    void OnLeaveWindow(wxMouseEvent& event);
329
[5809313]330    void OnLButtonDown(wxMouseEvent& event);
331    void OnLButtonUp(wxMouseEvent& event);
332    void OnMButtonDown(wxMouseEvent& event);
333    void OnMButtonUp(wxMouseEvent& event);
334    void OnRButtonDown(wxMouseEvent& event);
335    void OnRButtonUp(wxMouseEvent& event);
[582b10b]336    bool Animate();
[5809313]337
[4b1fc48]338    void OnKeyPress(wxKeyEvent &e);
339
[84cab34]340    void OnDisplayOverlappingNamesUpdate(wxUpdateUIEvent&);
341    void OnShowCrossesUpdate(wxUpdateUIEvent&);
342    void OnShowStationNamesUpdate(wxUpdateUIEvent&);
343    void OnShowSurveyLegsUpdate(wxUpdateUIEvent&);
[e8bc148]344    void OnShowSurfaceUpdate(wxUpdateUIEvent&);
345    void OnShowSurfaceDepthUpdate(wxUpdateUIEvent&);
346    void OnShowSurfaceDashedUpdate(wxUpdateUIEvent&);
[84cab34]347    void OnMoveEastUpdate(wxUpdateUIEvent&);
348    void OnMoveNorthUpdate(wxUpdateUIEvent&);
349    void OnMoveSouthUpdate(wxUpdateUIEvent&);
350    void OnMoveWestUpdate(wxUpdateUIEvent&);
351    void OnStartRotationUpdate(wxUpdateUIEvent&);
[7ebc3d1]352    void OnToggleRotationUpdate(wxUpdateUIEvent&);
[84cab34]353    void OnStopRotationUpdate(wxUpdateUIEvent&);
354    void OnReverseControlsUpdate(wxUpdateUIEvent&);
355    void OnReverseDirectionOfRotationUpdate(wxUpdateUIEvent&);
356    void OnSlowDownUpdate(wxUpdateUIEvent&);
357    void OnSpeedUpUpdate(wxUpdateUIEvent&);
358    void OnStepOnceAnticlockwiseUpdate(wxUpdateUIEvent&);
359    void OnStepOnceClockwiseUpdate(wxUpdateUIEvent&);
360    void OnDefaultsUpdate(wxUpdateUIEvent&);
361    void OnElevationUpdate(wxUpdateUIEvent&);
362    void OnHigherViewpointUpdate(wxUpdateUIEvent&);
363    void OnLowerViewpointUpdate(wxUpdateUIEvent&);
364    void OnPlanUpdate(wxUpdateUIEvent&);
365    void OnShiftDisplayDownUpdate(wxUpdateUIEvent&);
366    void OnShiftDisplayLeftUpdate(wxUpdateUIEvent&);
367    void OnShiftDisplayRightUpdate(wxUpdateUIEvent&);
368    void OnShiftDisplayUpUpdate(wxUpdateUIEvent&);
369    void OnZoomInUpdate(wxUpdateUIEvent&);
370    void OnZoomOutUpdate(wxUpdateUIEvent&);
371    void OnToggleScalebarUpdate(wxUpdateUIEvent&);
372    void OnToggleDepthbarUpdate(wxUpdateUIEvent&);
373    void OnViewCompassUpdate(wxUpdateUIEvent&);
[c300a04]374    void OnViewClinoUpdate(wxUpdateUIEvent&);
[c1cf79d]375    void OnViewGridUpdate(wxUpdateUIEvent&);
[fe444b8]376    void OnShowEntrancesUpdate(wxUpdateUIEvent&);
377    void OnShowExportedPtsUpdate(wxUpdateUIEvent&);
378    void OnShowFixedPtsUpdate(wxUpdateUIEvent&);
[e3513a5]379    void OnIndicatorsUpdate(wxUpdateUIEvent&);
[1fd2edb]380    void OnCancelDistLineUpdate(wxUpdateUIEvent&);
[84cab34]381
[7a89dc2]382    void OnToggleMetric();
383    void OnToggleMetricUpdate(wxUpdateUIEvent& cmd);
384       
385    void OnToggleDegrees();
386    void OnToggleDegreesUpdate(wxUpdateUIEvent& cmd);
[5757725]387
[09d50cc]388    void OnPrint(const wxString &filename, const wxString &title,
389                 const wxString &datestamp);
[301bbc1]390    bool OnExport(const wxString &filename, const wxString &title);
[09d50cc]391
[5809313]392private:
[84cab34]393    DECLARE_EVENT_TABLE()
[5809313]394};
395
396#endif
Note: See TracBrowser for help on using the repository browser.