source: git/src/gfxcore.h @ f1cbf74

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

aven: Add options dialog to "Export" similar to the one for "Print".

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