]>
Commit | Line | Data |
---|---|---|
981b2508 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: plot.h | |
3 | // Purpose: wxPlotWindow | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 12/1/2000 | |
7 | // Copyright: (c) Robert Roebling | |
8 | // RCS-ID: $Id$ | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_PLOT_H_ | |
13 | #define _WX_PLOT_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "plot.h" | |
17 | #endif | |
18 | ||
9b33fe02 VZ |
19 | #include "wx/defs.h" |
20 | ||
21 | #if wxUSE_PLOT | |
22 | ||
981b2508 | 23 | #include "wx/scrolwin.h" |
279ababf | 24 | #include "wx/event.h" |
b480710b | 25 | #include "wx/dynarray.h" |
981b2508 RR |
26 | |
27 | //----------------------------------------------------------------------------- | |
28 | // classes | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
279ababf RR |
31 | class WXDLLEXPORT wxPlotEvent; |
32 | class WXDLLEXPORT wxPlotCurve; | |
b480710b | 33 | class WXDLLEXPORT wxPlotValues; |
279ababf RR |
34 | class WXDLLEXPORT wxPlotArea; |
35 | class WXDLLEXPORT wxPlotXAxisArea; | |
36 | class WXDLLEXPORT wxPlotYAxisArea; | |
37 | class WXDLLEXPORT wxPlotWindow; | |
38 | ||
39 | //----------------------------------------------------------------------------- | |
40 | // consts | |
41 | //----------------------------------------------------------------------------- | |
42 | ||
43 | #define wxPLOT_X_AXIS 0x0004 | |
44 | #define wxPLOT_Y_AXIS 0x0008 | |
45 | #define wxPLOT_BUTTON_MOVE 0x0010 | |
46 | #define wxPLOT_BUTTON_ZOOM 0x0020 | |
47 | #define wxPLOT_BUTTON_ENLARGE 0x0040 | |
48 | ||
49 | #define wxPLOT_BUTTON_ALL (wxPLOT_BUTTON_MOVE|wxPLOT_BUTTON_ZOOM|wxPLOT_BUTTON_ENLARGE) | |
50 | #define wxPLOT_DEFAULT (wxPLOT_X_AXIS|wxPLOT_Y_AXIS | wxPLOT_BUTTON_ALL) | |
51 | ||
52 | //----------------------------------------------------------------------------- | |
53 | // wxPlotEvent | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
56 | class WXDLLEXPORT wxPlotEvent: public wxNotifyEvent | |
57 | { | |
58 | public: | |
59 | wxPlotEvent( wxEventType commandType = wxEVT_NULL, int id = 0 ); | |
9b33fe02 | 60 | |
279ababf RR |
61 | wxPlotCurve *GetCurve() |
62 | { return m_curve; } | |
63 | void SetCurve( wxPlotCurve *curve ) | |
64 | { m_curve = curve; } | |
9b33fe02 | 65 | |
279ababf RR |
66 | double GetZoom() |
67 | { return m_zoom; } | |
68 | void SetZoom( double zoom ) | |
69 | { m_zoom = zoom; } | |
9b33fe02 | 70 | |
279ababf RR |
71 | wxInt32 GetPosition() |
72 | { return m_position; } | |
73 | void SetPosition( wxInt32 pos ) | |
74 | { m_position = pos; } | |
9b33fe02 | 75 | |
279ababf RR |
76 | private: |
77 | wxPlotCurve *m_curve; | |
78 | double m_zoom; | |
79 | wxInt32 m_position; | |
80 | }; | |
981b2508 RR |
81 | |
82 | //----------------------------------------------------------------------------- | |
83 | // wxPlotCurve | |
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | class WXDLLEXPORT wxPlotCurve: public wxObject | |
87 | { | |
88 | public: | |
846e1424 | 89 | wxPlotCurve( int offsetY, double startY, double endY ); |
9b33fe02 | 90 | |
981b2508 RR |
91 | virtual wxInt32 GetStartX() = 0; |
92 | virtual wxInt32 GetEndX() = 0; | |
846e1424 RR |
93 | |
94 | virtual double GetY( wxInt32 x ) = 0; | |
95 | ||
96 | void SetStartY( double startY ) | |
97 | { m_startY = startY; } | |
98 | double GetStartY() | |
99 | { return m_startY; } | |
100 | void SetEndY( double endY ) | |
101 | { m_endY = endY; } | |
102 | double GetEndY() | |
103 | { return m_endY; } | |
104 | void SetOffsetY( int offsetY ) | |
105 | { m_offsetY = offsetY; } | |
981b2508 RR |
106 | int GetOffsetY() |
107 | { return m_offsetY; } | |
b480710b RR |
108 | |
109 | void SetPenNormal( const wxPen &pen ) | |
110 | { m_penNormal = pen; } | |
111 | void SetPenSelected( const wxPen &pen ) | |
112 | { m_penSelected = pen; } | |
9b33fe02 | 113 | |
981b2508 RR |
114 | private: |
115 | int m_offsetY; | |
846e1424 RR |
116 | double m_startY; |
117 | double m_endY; | |
b480710b RR |
118 | wxPen m_penNormal; |
119 | wxPen m_penSelected; | |
981b2508 RR |
120 | |
121 | DECLARE_ABSTRACT_CLASS(wxPlotCurve) | |
122 | }; | |
123 | ||
b480710b RR |
124 | //----------------------------------------------------------------------------- |
125 | // wxPlotOnOffCurve | |
126 | //----------------------------------------------------------------------------- | |
127 | ||
128 | class WXDLLEXPORT wxPlotOnOff | |
129 | { | |
130 | public: | |
131 | wxPlotOnOff() { } | |
132 | ||
133 | wxInt32 m_on; | |
134 | wxInt32 m_off; | |
135 | void *m_clientData; | |
136 | }; | |
137 | ||
138 | WX_DECLARE_EXPORTED_OBJARRAY(wxPlotOnOff, wxArrayPlotOnOff); | |
139 | ||
140 | class WXDLLEXPORT wxPlotOnOffCurve: public wxObject | |
141 | { | |
142 | public: | |
143 | wxPlotOnOffCurve( int offsetY ); | |
144 | ||
145 | wxInt32 GetStartX() | |
146 | { return m_minX; } | |
147 | wxInt32 GetEndX() | |
148 | { return m_maxX; } | |
149 | ||
150 | void SetOffsetY( int offsetY ) | |
151 | { m_offsetY = offsetY; } | |
152 | int GetOffsetY() | |
153 | { return m_offsetY; } | |
154 | ||
155 | void Add( wxInt32 on, wxInt32 off, void *clientData = NULL ); | |
156 | size_t GetCount(); | |
157 | ||
158 | wxInt32 GetOn( size_t index ); | |
159 | wxInt32 GetOff( size_t index ); | |
160 | void* GetClientData( size_t index ); | |
161 | wxPlotOnOff *GetAt( size_t index ); | |
162 | ||
163 | virtual void DrawOnLine( wxDC &dc, wxCoord y, wxCoord start, wxCoord end, void *clientData ); | |
164 | virtual void DrawOffLine( wxDC &dc, wxCoord y, wxCoord start, wxCoord end ); | |
165 | ||
166 | private: | |
167 | int m_offsetY; | |
168 | wxInt32 m_minX; | |
169 | wxInt32 m_maxX; | |
170 | ||
171 | wxArrayPlotOnOff m_marks; | |
172 | ||
173 | DECLARE_CLASS(wxPlotOnOffCurve) | |
174 | }; | |
175 | ||
981b2508 RR |
176 | //----------------------------------------------------------------------------- |
177 | // wxPlotArea | |
178 | //----------------------------------------------------------------------------- | |
179 | ||
180 | class WXDLLEXPORT wxPlotArea: public wxWindow | |
181 | { | |
182 | public: | |
183 | wxPlotArea() {} | |
184 | wxPlotArea( wxPlotWindow *parent ); | |
9b33fe02 | 185 | |
981b2508 RR |
186 | void OnPaint( wxPaintEvent &event ); |
187 | void OnMouse( wxMouseEvent &event ); | |
d3a809c7 RR |
188 | |
189 | void DrawCurve( wxDC *dc, wxPlotCurve *curve, int from = -1, int to = -1 ); | |
b480710b | 190 | void DrawOnOffCurve( wxDC *dc, wxPlotOnOffCurve *curve, int from = -1, int to = -1 ); |
d3a809c7 | 191 | void DeleteCurve( wxPlotCurve *curve, int from = -1, int to = -1 ); |
9b33fe02 | 192 | |
279ababf | 193 | virtual void ScrollWindow( int dx, int dy, const wxRect *rect ); |
9b33fe02 | 194 | |
981b2508 | 195 | private: |
279ababf RR |
196 | wxPlotWindow *m_owner; |
197 | bool m_zooming; | |
981b2508 RR |
198 | |
199 | DECLARE_CLASS(wxPlotArea) | |
200 | DECLARE_EVENT_TABLE() | |
201 | }; | |
202 | ||
279ababf RR |
203 | //----------------------------------------------------------------------------- |
204 | // wxPlotXAxisArea | |
205 | //----------------------------------------------------------------------------- | |
206 | ||
207 | class WXDLLEXPORT wxPlotXAxisArea: public wxWindow | |
208 | { | |
209 | public: | |
210 | wxPlotXAxisArea() {} | |
211 | wxPlotXAxisArea( wxPlotWindow *parent ); | |
9b33fe02 | 212 | |
279ababf RR |
213 | void OnPaint( wxPaintEvent &event ); |
214 | void OnMouse( wxMouseEvent &event ); | |
9b33fe02 | 215 | |
279ababf RR |
216 | private: |
217 | wxPlotWindow *m_owner; | |
218 | ||
219 | DECLARE_CLASS(wxPlotXAxisArea) | |
220 | DECLARE_EVENT_TABLE() | |
221 | }; | |
222 | ||
223 | //----------------------------------------------------------------------------- | |
224 | // wxPlotYAxisArea | |
225 | //----------------------------------------------------------------------------- | |
226 | ||
227 | class WXDLLEXPORT wxPlotYAxisArea: public wxWindow | |
228 | { | |
229 | public: | |
230 | wxPlotYAxisArea() {} | |
231 | wxPlotYAxisArea( wxPlotWindow *parent ); | |
9b33fe02 | 232 | |
279ababf RR |
233 | void OnPaint( wxPaintEvent &event ); |
234 | void OnMouse( wxMouseEvent &event ); | |
9b33fe02 | 235 | |
279ababf RR |
236 | private: |
237 | wxPlotWindow *m_owner; | |
238 | ||
239 | DECLARE_CLASS(wxPlotYAxisArea) | |
240 | DECLARE_EVENT_TABLE() | |
241 | }; | |
242 | ||
981b2508 RR |
243 | //----------------------------------------------------------------------------- |
244 | // wxPlotWindow | |
245 | //----------------------------------------------------------------------------- | |
246 | ||
247 | class WXDLLEXPORT wxPlotWindow: public wxScrolledWindow | |
248 | { | |
249 | public: | |
250 | wxPlotWindow() {} | |
279ababf | 251 | wxPlotWindow( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, int flags = wxPLOT_DEFAULT ); |
981b2508 | 252 | ~wxPlotWindow(); |
9b33fe02 | 253 | |
279ababf RR |
254 | // curve accessors |
255 | // --------------- | |
9b33fe02 | 256 | |
981b2508 | 257 | void Add( wxPlotCurve *curve ); |
b480710b RR |
258 | void Delete( wxPlotCurve* curve ); |
259 | ||
981b2508 RR |
260 | size_t GetCount(); |
261 | wxPlotCurve *GetAt( size_t n ); | |
262 | ||
263 | void SetCurrent( wxPlotCurve* current ); | |
264 | wxPlotCurve *GetCurrent(); | |
9b33fe02 | 265 | |
b480710b RR |
266 | // mark list accessors |
267 | // ------------------- | |
268 | ||
269 | void Add( wxPlotOnOffCurve *curve ); | |
270 | void Delete( wxPlotOnOffCurve* curve ); | |
271 | ||
272 | size_t GetOnOffCurveCount(); | |
273 | wxPlotOnOffCurve *GetOnOffCurveAt( size_t n ); | |
9b33fe02 | 274 | |
279ababf RR |
275 | // vertical representation |
276 | // ----------------------- | |
9b33fe02 | 277 | |
d3a809c7 RR |
278 | void Move( wxPlotCurve* curve, int pixels_up ); |
279 | void Enlarge( wxPlotCurve *curve, double factor ); | |
280 | ||
279ababf RR |
281 | // horizontal representation |
282 | // ------------------------- | |
9b33fe02 | 283 | |
279ababf RR |
284 | void SetUnitsPerValue( double upv ); |
285 | double GetUnitsPerValue() | |
286 | { return m_xUnitsPerValue; } | |
9b33fe02 | 287 | |
279ababf RR |
288 | void SetZoom( double zoom ); |
289 | double GetZoom() | |
290 | { return m_xZoom; } | |
9b33fe02 | 291 | |
530a7383 RR |
292 | // options |
293 | // ------- | |
294 | ||
295 | void SetScrollOnThumbRelease( bool scrollOnThumbRelease = TRUE ) | |
296 | { m_scrollOnThumbRelease = scrollOnThumbRelease; } | |
297 | bool GetScrollOnThumbRelease() | |
298 | { return m_scrollOnThumbRelease; } | |
9b33fe02 | 299 | |
530a7383 RR |
300 | void SetEnlargeAroundWindowCentre( bool enlargeAroundWindowCentre = TRUE ) |
301 | { m_enlargeAroundWindowCentre = enlargeAroundWindowCentre; } | |
302 | bool GetEnlargeAroundWindowCentre() | |
303 | { return m_enlargeAroundWindowCentre; } | |
304 | ||
279ababf RR |
305 | // events (may be overridden) |
306 | // -------------------------- | |
307 | ||
d3a809c7 RR |
308 | void OnMoveUp( wxCommandEvent& event ); |
309 | void OnMoveDown( wxCommandEvent& event ); | |
9b33fe02 | 310 | |
279ababf RR |
311 | void OnEnlarge( wxCommandEvent& event ); |
312 | void OnShrink( wxCommandEvent& event ); | |
313 | void OnZoomIn( wxCommandEvent& event ); | |
314 | void OnZoomOut( wxCommandEvent& event ); | |
9b33fe02 | 315 | |
279ababf | 316 | void OnScroll2( wxScrollWinEvent& event ); |
9b33fe02 | 317 | |
279ababf RR |
318 | // utilities |
319 | // --------- | |
9b33fe02 | 320 | |
279ababf RR |
321 | void RedrawEverything(); |
322 | void RedrawXAxis(); | |
d3a809c7 | 323 | void RedrawYAxis(); |
9b33fe02 | 324 | |
279ababf | 325 | void ResetScrollbar(); |
9b33fe02 | 326 | |
981b2508 | 327 | private: |
f6bcfd97 BP |
328 | friend class wxPlotArea; |
329 | friend class wxPlotXAxisArea; | |
330 | friend class wxPlotYAxisArea; | |
9b33fe02 | 331 | |
279ababf RR |
332 | double m_xUnitsPerValue; |
333 | double m_xZoom; | |
9b33fe02 | 334 | |
279ababf | 335 | wxList m_curves; |
b480710b RR |
336 | wxList m_onOffCurves; |
337 | ||
279ababf RR |
338 | wxPlotArea *m_area; |
339 | wxPlotXAxisArea *m_xaxis; | |
340 | wxPlotYAxisArea *m_yaxis; | |
341 | wxPlotCurve *m_current; | |
9b33fe02 | 342 | |
530a7383 RR |
343 | bool m_scrollOnThumbRelease; |
344 | bool m_enlargeAroundWindowCentre; | |
981b2508 RR |
345 | |
346 | DECLARE_CLASS(wxPlotWindow) | |
347 | DECLARE_EVENT_TABLE() | |
348 | }; | |
349 | ||
279ababf | 350 | // ---------------------------------------------------------------------------- |
669f7a11 | 351 | // plot event macros |
279ababf RR |
352 | // ---------------------------------------------------------------------------- |
353 | ||
669f7a11 JS |
354 | typedef void (wxEvtHandler::*wxPlotEventFunction)(wxPlotEvent&); |
355 | ||
356 | #define EVT_PLOT(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
357 | #define EVT_PLOT_SEL_CHANGING(id, fn) { wxEVT_PLOT_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
358 | #define EVT_PLOT_SEL_CHANGED(id, fn) { wxEVT_PLOT_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
359 | #define EVT_PLOT_CLICKED(id, fn) { wxEVT_PLOT_CLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
360 | #define EVT_PLOT_DOUBLECLICKED(id, fn) { wxEVT_PLOT_DOUBLECLICKED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
361 | #define EVT_PLOT_ZOOM_IN(id, fn) { wxEVT_PLOT_ZOOM_IN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
362 | #define EVT_PLOT_ZOOM_OUT(id, fn) { wxEVT_PLOT_ZOOM_OUT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
363 | #define EVT_PLOT_VALUE_SEL_CREATING(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
364 | #define EVT_PLOT_VALUE_SEL_CREATED(id, fn) { wxEVT_PLOT_VALUE_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
365 | #define EVT_PLOT_VALUE_SEL_CHANGING(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
366 | #define EVT_PLOT_VALUE_SEL_CHANGED(id, fn) { wxEVT_PLOT_VALUE_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
367 | #define EVT_PLOT_AREA_SEL_CREATING(id, fn) { wxEVT_PLOT_AREA_SEL_CREATING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
368 | #define EVT_PLOT_AREA_SEL_CREATED(id, fn) { wxEVT_PLOT_AREA_SEL_CREATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
369 | #define EVT_PLOT_AREA_SEL_CHANGING(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGING, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
370 | #define EVT_PLOT_AREA_SEL_CHANGED(id, fn) { wxEVT_PLOT_AREA_SEL_CHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
371 | #define EVT_PLOT_BEGIN_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
372 | #define EVT_PLOT_END_X_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_X_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
373 | #define EVT_PLOT_BEGIN_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_BEGIN_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
374 | #define EVT_PLOT_END_Y_LABEL_EDIT(id, fn) { wxEVT_PLOT_END_Y_LABEL_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
375 | #define EVT_PLOT_BEGIN_TITLE_EDIT(id, fn) { wxEVT_PLOT_BEGIN_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
376 | #define EVT_PLOT_END_TITLE_EDIT(id, fn) { wxEVT_PLOT_END_TITLE_EDIT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxPlotEventFunction) & fn, (wxObject *) NULL }, | |
279ababf | 377 | |
9b33fe02 VZ |
378 | #endif // wxUSE_PLOT |
379 | ||
981b2508 RR |
380 | #endif |
381 | // _WX_PLOT_H_ |