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