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