Main MRPT website > C++ reference for MRPT 1.4.0
mathplot.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 /////////////////////////////////////////////////////////////////////////////
10 // Name: mathplot.cpp
11 // Purpose: Framework for plotting in wxWindows
12 // Original Author: David Schalig
13 // Maintainer: Davide Rondini
14 // Contributors: Jose Luis Blanco, Val Greene
15 // Created: 21/07/2003
16 // Last edit: 22/02/2009
17 // Copyright: (c) David Schalig, Davide Rondini
18 // Licence: wxWindows licence
19 /////////////////////////////////////////////////////////////////////////////
20 
21 #ifndef _MP_MATHPLOT_H_
22 #define _MP_MATHPLOT_H_
23 
24 // JL: This is VERY ugly, but ask MS why we cannot export a DLL class with STL members !!
25 #if defined(_MSC_VER)
26  #pragma warning(push)
27  #pragma warning(disable:4251)
28 #endif
29 
30 /** @file mathplot.h */
31 /** @mainpage wxMathPlot
32  wxMathPlot is a framework for mathematical graph plotting in wxWindows.
33 
34  The framework is designed for convenience and ease of use.
35 
36  @section screenshots Screenshots
37  <a href="http://wxmathplot.sourceforge.net/screenshot.shtml" >Go to the screenshots page.</a>
38 
39  @section overview Overview
40  The heart of wxMathPlot is mpWindow, which is a 2D canvas for plot layers.
41  mpWindow can be embedded as subwindow in a wxPane, a wxFrame, or any other wxWindow.
42  mpWindow provides a zoomable and moveable view of the layers. The current view can
43  be controlled with the mouse, the scrollbars, and a context menu.
44 
45  Plot layers are implementations of the abstract base class mpLayer. Those can
46  be function plots, scale rulers, or any other vector data visualisation. wxMathPlot provides two mpLayer implementations for plotting horizontal and vertical rulers: mpScaleX and mpScaleY.
47  For convenient function plotting a series of classes derived from mpLayer are provided, like mpFX, mpProfile, mpLegend and so on. These base classes already come with plot code, user's own functions can be implemented by overriding just one member for retrieving a function value.
48 
49  mpWindow has built-in support for mouse-based pan and zoom through intuitive combinations of buttons and the mouse wheel. It also incorporates an optional double buffering mechanism to avoid flicker. Plots can be easily sent to printer evices or exported in bitmap formats like PNG, BMP or JPEG.
50 
51  @section coding Coding conventions
52  wxMathPlot sticks to wxWindow's coding conventions. All entities defined by wxMathPlot have the prefix <i>mp</i>.
53 
54  @section author Author and license
55  wxMathPlot is published under the terms of the wxWindow license.<br>
56  The original author is David Schalig <mrhill@users.sourceforge.net>.<br>
57  From June 2007 the project is maintained by Davide Rondini <cdron77@users.sourceforge.net>.<br>
58  Authors can be contacted via the wxMathPlot's homepage at
59  https://sourceforge.net/projects/wxmathplot<br>
60  Contributors:<br>
61  Jose Luis Blanco, Val Greene.<br>
62 */
63 
64 //this definition uses windows dll to export function.
65 //WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
66 //mathplot_EXPORTS will be defined by cmake
67 //#ifdef mathplot_EXPORTS
68 // #define WXDLLIMPEXP_MATHPLOT WXEXPORT
69 // #define WXDLLIMPEXP_DATA_MATHPLOT(type) WXEXPORT type
70 //#else // not making DLL
71 // #define WXDLLIMPEXP_MATHPLOT
72 // #define WXDLLIMPEXP_DATA_MATHPLOT(type) type
73 //#endif
74 
75 // Hack for MRPT: Link as part of mrpt-gui itself.
76 #include <mrpt/gui/link_pragmas.h>
77 #define WXDLLIMPEXP_MATHPLOT GUI_IMPEXP
78 
79 
80 #if defined(__GNUG__) && !defined(__clang__)
81 #pragma interface "mathplot.h"
82 #endif
83 
84 #include <vector>
85 
86 // #include <wx/wx.h>
87 #include <wx/defs.h>
88 #include <wx/menu.h>
89 #include <wx/scrolwin.h>
90 #include <wx/event.h>
91 #include <wx/dynarray.h>
92 #include <wx/pen.h>
93 #include <wx/dcmemory.h>
94 #include <wx/string.h>
95 #include <wx/print.h>
96 #include <wx/image.h>
97 
98 
99 #include <deque>
100 
101 // For memory leak debug
102 #ifdef _WINDOWS
103 #ifdef _DEBUG
104 #include <crtdbg.h>
105 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
106 #else
107 #define DEBUG_NEW new
108 #endif // _DEBUG
109 #endif // _WINDOWS
110 
111 // Separation for axes when set close to border
112 #define X_BORDER_SEPARATION 40
113 #define Y_BORDER_SEPARATION 60
114 
115 //-----------------------------------------------------------------------------
116 // classes
117 //-----------------------------------------------------------------------------
118 
129 
130 /** Command IDs used by mpWindow */
131 enum
132 {
133  mpID_FIT = 2000, //!< Fit view to match bounding box of all layers
134  mpID_ZOOM_IN, //!< Zoom into view at clickposition / window center
135  mpID_ZOOM_OUT, //!< Zoom out
136  mpID_CENTER, //!< Center view on click position
137  mpID_LOCKASPECT, //!< Lock x/y scaling aspect
138  mpID_HELP_MOUSE, //!< Shows information about the mouse commands
139  mpID_PRINT //!< JL: Prints the graph
140 };
141 
142 //-----------------------------------------------------------------------------
143 // mpLayer
144 //-----------------------------------------------------------------------------
145 
146 typedef enum __mp_Layer_Type {
147  mpLAYER_UNDEF, //!< Layer type undefined
148  mpLAYER_AXIS, //!< Axis type layer
149  mpLAYER_PLOT, //!< Plot type layer
150  mpLAYER_INFO, //!< Info box type layer
151  mpLAYER_BITMAP //!< Bitmap type layer
152 } mpLayerType;
153 
154 /** Plot layer, abstract base class.
155  Any number of mpLayer implementations can be attached to mpWindow.
156  Examples for mpLayer implementations are function graphs, or scale rulers.
157 
158  For convenience mpLayer defines a name, a font (wxFont), a pen (wxPen),
159  and a continuity property (bool) as class members.
160  The default values at constructor are the default font, a black pen, and
161  continuity set to false (draw separate points).
162  These may or may not be used by implementations.
163 */
164 class WXDLLIMPEXP_MATHPLOT mpLayer : public wxObject
165 {
166 public:
167  mpLayer();
168 
169  virtual ~mpLayer() {};
170 
171  /** Check whether this layer has a bounding box.
172  The default implementation returns \a TRUE. Override and return
173  FALSE if your mpLayer implementation should be ignored by the calculation
174  of the global bounding box for all layers in a mpWindow.
175  @retval TRUE Has bounding box
176  @retval FALSE Has not bounding box
177  */
178  virtual bool HasBBox() { return TRUE; }
179 
180  /** Check whether the layer is an info box.
181  The default implementation returns \a FALSE. It is overrided to \a TRUE for mpInfoLayer
182  class and its derivative. It is necessary to define mouse actions behaviour over
183  info boxes.
184  @return whether the layer is an info boxes
185  @sa mpInfoLayer::IsInfo */
186  virtual bool IsInfo() { return false; };
187 
188  /** Get inclusive left border of bounding box.
189  @return Value
190  */
191  virtual double GetMinX() { return -1.0; }
192 
193  /** Get inclusive right border of bounding box.
194  @return Value
195  */
196  virtual double GetMaxX() { return 1.0; }
197 
198  /** Get inclusive bottom border of bounding box.
199  @return Value
200  */
201  virtual double GetMinY() { return -1.0; }
202 
203  /** Get inclusive top border of bounding box.
204  @return Value
205  */
206  virtual double GetMaxY() { return 1.0; }
207 
208  /** Plot given view of layer to the given device context.
209  An implementation of this function has to transform layer coordinates to
210  wxDC coordinates based on the view parameters retrievable from the mpWindow
211  passed in \a w.
212  Note that the public methods of mpWindow: x2p,y2p and p2x,p2y are already provided
213  which transform layer coordinates to DC pixel coordinates, and <b>user code should rely
214  on them</b> for portability and future changes to be applied transparently, instead of
215  implementing the following formulas manually.
216 
217  The passed device context \a dc has its coordinate origin set to the top-left corner
218  of the visible area (the default). The coordinate orientation is as shown in the
219  following picture:
220  <pre>
221  (wxDC origin 0,0)
222  x-------------> ascending X ----------------+
223  | |
224  | |
225  V ascending Y |
226  | |
227  | |
228  | |
229  +-------------------------------------------+ <-- right-bottom corner of the mpWindow visible area.
230  </pre>
231  Note that Y ascends in downward direction, whereas the usual vertical orientation
232  for mathematical plots is vice versa. Thus Y-orientation will be swapped usually,
233  when transforming between wxDC and mpLayer coordinates. This change of coordinates
234  is taken into account in the methods p2x,p2y,x2p,y2p.
235 
236  <b> Rules for transformation between mpLayer and wxDC coordinates </b>
237  @code
238  dc_X = (layer_X - mpWindow::GetPosX()) * mpWindow::GetScaleX()
239  dc_Y = (mpWindow::GetPosY() - layer_Y) * mpWindow::GetScaleY() // swapping Y-orientation
240 
241  layer_X = (dc_X / mpWindow::GetScaleX()) + mpWindow::GetPosX() // scale guaranteed to be not 0
242  layer_Y = mpWindow::GetPosY() - (dc_Y / mpWindow::GetScaleY()) // swapping Y-orientation
243  @endcode
244 
245  @param dc Device context to plot to.
246  @param w View to plot. The visible area can be retrieved from this object.
247  @sa mpWindow::p2x,mpWindow::p2y,mpWindow::x2p,mpWindow::y2p
248  */
249  virtual void Plot(wxDC & dc, mpWindow & w) = 0;
250 
251  /** Get layer name.
252  @return Name
253  */
254  wxString GetName() const { return m_name; }
255 
256  /** Get font set for this layer.
257  @return Font
258  */
259  const wxFont& GetFont() const { return m_font; }
260 
261  /** Get pen set for this layer.
262  @return Pen
263  */
264  const wxPen& GetPen() const { return m_pen; }
265 
266  /** Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).
267  * @sa GetContinuity
268  */
269  void SetContinuity(bool continuity) {m_continuous = continuity;}
270 
271  /** Gets the 'continuity' property of the layer.
272  * @sa SetContinuity
273  */
274  bool GetContinuity() const {return m_continuous;}
275 
276  /** Shows or hides the text label with the name of the layer (default is visible).
277  */
278  void ShowName(bool show) { m_showName = show; };
279 
280  /** Set layer name
281  @param name Name, will be copied to internal class member
282  */
283  void SetName(wxString name) { m_name = name; }
284 
285  /** Set layer font
286  @param font Font, will be copied to internal class member
287  */
288  void SetFont(wxFont& font) { m_font = font; }
289 
290  /** Set layer pen
291  @param pen Pen, will be copied to internal class member
292  */
293  void SetPen(wxPen pen) { m_pen = pen; }
294 
295  /** Set Draw mode: inside or outside margins. Default is outside, which allows the layer to draw up to the mpWindow border.
296  @param drawModeOutside The draw mode to be set */
297  void SetDrawOutsideMargins(bool drawModeOutside) { m_drawOutsideMargins = drawModeOutside; };
298 
299  /** Get Draw mode: inside or outside margins.
300  @return The draw mode */
301  bool GetDrawOutsideMargins() { return m_drawOutsideMargins; };
302 
303  /** Get a small square bitmap filled with the colour of the pen used in the layer. Useful to create legends or similar reference to the layers.
304  @param side side length in pixels
305  @return a wxBitmap filled with layer's colour */
306  wxBitmap GetColourSquare(int side = 16);
307 
308  /** Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.
309  @return An integer indicating layer type */
310  mpLayerType GetLayerType() { return m_type; };
311 
312  /** Checks whether the layer is visible or not.
313  @return \a true if visible */
314  bool IsVisible() {return m_visible; };
315 
316  /** Sets layer visibility.
317  @param show visibility bool. */
318  void SetVisible(bool show) { m_visible = show; };
319 
320  /** Get brush set for this layer.
321  @return brush. */
322  const wxBrush& GetBrush() const { return m_brush; };
323 
324  /** Set layer brush
325  @param brush brush, will be copied to internal class member */
326  void SetBrush(wxBrush brush) { m_brush = brush; };
327 
328 protected:
329  wxFont m_font; //!< Layer's font
330  wxPen m_pen; //!< Layer's pen
331  wxBrush m_brush; //!< Layer's brush
332  wxString m_name; //!< Layer's name
333  bool m_continuous; //!< Specify if the layer will be plotted as a continuous line or a set of points.
334  bool m_showName; //!< States whether the name of the layer must be shown (default is true).
335  bool m_drawOutsideMargins; //!< select if the layer should draw only inside margins or over all DC
336  mpLayerType m_type; //!< Define layer type, which is assigned by constructor
337  bool m_visible; //!< Toggles layer visibility
338  DECLARE_DYNAMIC_CLASS(mpLayer)
339 };
340 
341 
342 //-----------------------------------------------------------------------------
343 // mpInfoLayer
344 //-----------------------------------------------------------------------------
345 
346 /** @class mpInfoLayer
347  @brief Base class to create small rectangular info boxes
348  mpInfoLayer is the base class to create a small rectangular info box in transparent overlay over plot layers. It is used to implement objects like legends.
349 */
351 {
352 public:
353  /** Default constructor. */
354  mpInfoLayer();
355 
356  /** Complete constructor.
357  @param rect Sets the initial size rectangle of the layer.
358  @param brush pointer to a fill brush. Default is transparent */
359  mpInfoLayer(wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH);
360 
361  /** Destructor */
362  virtual ~mpInfoLayer();
363 
364  /** Updates the content of the info box. Should be overidden by derived classes.
365  Update may behave in different ways according to the type of event which called it.
366  @param w parent mpWindow from which to obtain informations
367  @param event The event which called the update. */
368  virtual void UpdateInfo(mpWindow& w, wxEvent& event);
369 
370  /** mpInfoLayer has not bounding box. @sa mpLayer::HasBBox
371  @return always \a FALSE */
372  virtual bool HasBBox() { return false; };
373 
374  /** Plot method. Can be overidden by derived classes.
375  @param dc the device content where to plot
376  @param w the window to plot
377  @sa mpLayer::Plot */
378  virtual void Plot(wxDC & dc, mpWindow & w);
379 
380  /** Specifies that this is an Info box layer.
381  @return always \a TRUE
382  @sa mpLayer::IsInfo */
383  virtual bool IsInfo() { return true; };
384 
385  /** Checks whether a point is inside the info box rectangle.
386  @param point The point to be checked
387  @return \a true if the point is inside the bounding box */
388  virtual bool Inside(wxPoint& point);
389 
390  /** Moves the layer rectangle of given pixel deltas.
391  @param delta The wxPoint container for delta coordinates along x and y. Units are in pixels. */
392  virtual void Move(wxPoint delta);
393 
394  /** Updates the rectangle reference point. Used by internal methods of mpWindow to correctly move mpInfoLayers. */
395  virtual void UpdateReference();
396 
397  /** Returns the position of the upper left corner of the box (in pixels)
398  @return The rectangle position */
399  wxPoint GetPosition();
400 
401  /** Returns the size of the box (in pixels)
402  @return The rectangle size */
403  wxSize GetSize();
404 
405  /** Returns the current rectangle coordinates.
406  @return The info layer rectangle */
407  const wxRect& GetRectangle() { return m_dim; };
408 
409 protected:
410  wxRect m_dim; //!< The bounding rectangle of the box. It may be resized dynamically by the Plot method.
411  wxPoint m_reference; //!< Holds the reference point for movements
412  wxBrush m_brush; //!< The brush to be used for the background
413  int m_winX, m_winY; //!< Holds the mpWindow size. Used to rescale position when window is resized.
414 
415  DECLARE_DYNAMIC_CLASS(mpInfoLayer)
416 };
417 
418 /** @class mpInfoCoords
419  @brief Implements an overlay box which shows the mouse coordinates in plot units.
420  When an mpInfoCoords layer is activated, when mouse is moved over the mpWindow, its coordinates (in mpWindow units, not pixels) are continuously reported inside the layer box. */
422 {
423 public:
424  /** Default constructor */
425  mpInfoCoords();
426  /** Complete constructor, setting initial rectangle and background brush.
427  @param rect The initial bounding rectangle.
428  @param brush The wxBrush to be used for box background: default is transparent */
429  mpInfoCoords(wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH);
430 
431  /** Default destructor */
432  ~mpInfoCoords();
433 
434  /** Updates the content of the info box. It is used to update coordinates.
435  @param w parent mpWindow from which to obtain information
436  @param event The event which called the update. */
437  virtual void UpdateInfo(mpWindow& w, wxEvent& event);
438 
439  /** Plot method.
440  @param dc the device content where to plot
441  @param w the window to plot
442  @sa mpLayer::Plot */
443  virtual void Plot(wxDC & dc, mpWindow & w);
444 
445 protected:
446  wxString m_content; //!< string holding the coordinates to be drawn.
447 };
448 
449 /** @class mpInfoLegend
450  @brief Implements the legend to be added to the plot
451  This layer allows you to add a legend to describe the plots in the window. The legend uses the layer name as a label, and displays only layers of type mpLAYER_PLOT. */
453 {
454 public:
455  /** Default constructor */
456  mpInfoLegend();
457 
458  /** Complete constructor, setting initial rectangle and background brush.
459  @param rect The initial bounding rectangle.
460  @param brush The wxBrush to be used for box background: default is transparent
461  @sa mpInfoLayer::mpInfoLayer */
462  mpInfoLegend(wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH);
463 
464  /** Default destructor */
465  ~mpInfoLegend();
466 
467  /** Updates the content of the info box. Unused in this class.
468  @param w parent mpWindow from which to obtain information
469  @param event The event which called the update. */
470  virtual void UpdateInfo(mpWindow& w, wxEvent& event);
471 
472  /** Plot method.
473  @param dc the device content where to plot
474  @param w the window to plot
475  @sa mpLayer::Plot */
476  virtual void Plot(wxDC & dc, mpWindow & w);
477 
478 protected:
479 
480 };
481 
482 
483 //-----------------------------------------------------------------------------
484 // mpLayer implementations - functions
485 //-----------------------------------------------------------------------------
486 
487 /** @name Label alignment constants
488 @{*/
489 
490 /** @internal */
491 #define mpALIGNMASK 0x03
492 /** Aligns label to the right. For use with mpFX. */
493 #define mpALIGN_RIGHT 0x00
494 /** Aligns label to the center. For use with mpFX and mpFY. */
495 #define mpALIGN_CENTER 0x01
496 /** Aligns label to the left. For use with mpFX. */
497 #define mpALIGN_LEFT 0x02
498 /** Aligns label to the top. For use with mpFY. */
499 #define mpALIGN_TOP mpALIGN_RIGHT
500 /** Aligns label to the bottom. For use with mpFY. */
501 #define mpALIGN_BOTTOM mpALIGN_LEFT
502 /** Aligns X axis to bottom border. For mpScaleX */
503 #define mpALIGN_BORDER_BOTTOM 0x04
504 /** Aligns X axis to top border. For mpScaleX */
505 #define mpALIGN_BORDER_TOP 0x05
506 /** Set label for X axis in normal mode */
507 #define mpX_NORMAL 0x00
508 /** Set label for X axis in time mode: the value is represented as minutes:seconds.milliseconds if time is less than 2 minutes, hours:minutes:seconds otherwise. */
509 #define mpX_TIME 0x01
510 /** Set label for X axis in hours mode: the value is always represented as hours:minutes:seconds. */
511 #define mpX_HOURS 0x02
512 /** Set label for X axis in date mode: the value is always represented as yyyy-mm-dd. */
513 #define mpX_DATE 0x03
514 /** Set label for X axis in datetime mode: the value is always represented as yyyy-mm-ddThh:mm:ss. */
515 #define mpX_DATETIME 0x04
516 /** Aligns Y axis to left border. For mpScaleY */
517 #define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
518 /** Aligns Y axis to right border. For mpScaleY */
519 #define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
520 /** Aligns label to north-east. For use with mpFXY. */
521 #define mpALIGN_NE 0x00
522 /** Aligns label to north-west. For use with mpFXY. */
523 #define mpALIGN_NW 0x01
524 /** Aligns label to south-west. For use with mpFXY. */
525 #define mpALIGN_SW 0x02
526 /** Aligns label to south-east. For use with mpFXY. */
527 #define mpALIGN_SE 0x03
528 
529 /*@}*/
530 
531 /** @name mpLayer implementations - functions
532 @{*/
533 
534 /** Abstract base class providing plot and labeling functionality for functions F:X->Y.
535  Override mpFX::GetY to implement a function.
536  Optionally implement a constructor and pass a name (label) and a label alignment
537  to the constructor mpFX::mpFX. If the layer name is empty, no label will be plotted.
538 */
540 {
541 public:
542  /** @param name Label
543  @param flags Label alignment, pass one of #mpALIGN_RIGHT, #mpALIGN_CENTER, #mpALIGN_LEFT.
544  */
545  mpFX(wxString name = wxEmptyString, int flags = mpALIGN_RIGHT);
546 
547  /** Get function value for argument.
548  Override this function in your implementation.
549  @param x Argument
550  @return Function value
551  */
552  virtual double GetY( double x ) = 0;
553 
554  /** Layer plot handler.
555  This implementation will plot the function in the visible area and
556  put a label according to the aligment specified.
557  */
558  virtual void Plot(wxDC & dc, mpWindow & w);
559 
560 protected:
561  int m_flags; //!< Holds label alignment
562 
563  DECLARE_DYNAMIC_CLASS(mpFX)
564 };
565 
566 /** Abstract base class providing plot and labeling functionality for functions F:Y->X.
567  Override mpFY::GetX to implement a function.
568  Optionally implement a constructor and pass a name (label) and a label alignment
569  to the constructor mpFY::mpFY. If the layer name is empty, no label will be plotted.
570 */
572 {
573 public:
574  /** @param name Label
575  @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP.
576  */
577  mpFY(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
578 
579  /** Get function value for argument.
580  Override this function in your implementation.
581  @param y Argument
582  @return Function value
583  */
584  virtual double GetX( double y ) = 0;
585 
586  /** Layer plot handler.
587  This implementation will plot the function in the visible area and
588  put a label according to the aligment specified.
589  */
590  virtual void Plot(wxDC & dc, mpWindow & w);
591 
592 protected:
593  int m_flags; //!< Holds label alignment
594 
595  DECLARE_DYNAMIC_CLASS(mpFY)
596 };
597 
598 /** Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
599  Locus argument N is assumed to be in range 0 .. MAX_N, and implicitly derived by enumerating
600  all locus values. Override mpFXY::Rewind and mpFXY::GetNextXY to implement a locus.
601  Optionally implement a constructor and pass a name (label) and a label alignment
602  to the constructor mpFXY::mpFXY. If the layer name is empty, no label will be plotted.
603 */
605 {
606 public:
607  /** @param name Label
608  @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
609  */
610  mpFXY(wxString name = wxEmptyString, int flags = mpALIGN_NE);
611 
612  /** Rewind value enumeration with mpFXY::GetNextXY.
613  Override this function in your implementation.
614  */
615  virtual void Rewind() = 0;
616 
617  /** Get locus value for next N.
618  Override this function in your implementation.
619  @param x Returns X value
620  @param y Returns Y value
621  */
622  virtual bool GetNextXY(double & x, double & y) = 0;
623 
624  /** Layer plot handler.
625  This implementation will plot the locus in the visible area and
626  put a label according to the alignment specified.
627  */
628  virtual void Plot(wxDC & dc, mpWindow & w);
629 
630 
631 protected:
632  int m_flags; //!< Holds label alignment
633 
634  // Data to calculate label positioning
635  wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
636  //int drawnPoints;
637 
638  /** Update label positioning data
639  @param xnew New x coordinate
640  @param ynew New y coordinate
641  */
642  void UpdateViewBoundary(wxCoord xnew, wxCoord ynew);
643 
644  DECLARE_DYNAMIC_CLASS(mpFXY)
645 };
646 
647 /** Abstract base class providing plot and labeling functionality for functions F:Y->X.
648  Override mpProfile::GetX to implement a function.
649  This class is similar to mpFY, but the Plot method is different. The plot is in fact represented by lines instead of points, which gives best rendering of rapidly-varying functions, and in general, data which are not so close one to another.
650  Optionally implement a constructor and pass a name (label) and a label alignment
651  to the constructor mpProfile::mpProfile. If the layer name is empty, no label will be plotted.
652 */
654 {
655 public:
656  /** @param name Label
657  @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP.
658  */
659  mpProfile(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
660 
661  /** Get function value for argument.
662  Override this function in your implementation.
663  @param x Argument
664  @return Function value
665  */
666  virtual double GetY( double x ) = 0;
667 
668  /** Layer plot handler.
669  This implementation will plot the function in the visible area and
670  put a label according to the aligment specified.
671  */
672  virtual void Plot(wxDC & dc, mpWindow & w);
673 
674 protected:
675  int m_flags; //!< Holds label alignment
676 
677  DECLARE_DYNAMIC_CLASS(mpProfile)
678 };
679 
680 /*@}*/
681 
682 //-----------------------------------------------------------------------------
683 // mpLayer implementations - furniture (scales, ...)
684 //-----------------------------------------------------------------------------
685 
686 /** @name mpLayer implementations - furniture (scales, ...)
687 @{*/
688 
689 /** Plot layer implementing a x-scale ruler.
690  The ruler is fixed at Y=0 in the coordinate system. A label is plotted at
691  the bottom-right hand of the ruler. The scale numbering automatically
692  adjusts to view and zoom factor.
693 */
695 {
696 public:
697  /** Full constructor.
698  @param name Label to plot by the ruler
699  @param flags Set the position of the scale with respect to the window.
700  @param ticks Select ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid.
701  @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */
702  mpScaleX(wxString name = wxT("X"), int flags = mpALIGN_CENTER, bool ticks = true, unsigned int type = mpX_NORMAL);
703 
704  /** Layer plot handler.
705  This implementation will plot the ruler adjusted to the visible area. */
706  virtual void Plot(wxDC & dc, mpWindow & w);
707 
708  /** Check whether this layer has a bounding box.
709  This implementation returns \a FALSE thus making the ruler invisible
710  to the plot layer bounding box calculation by mpWindow. */
711  virtual bool HasBBox() { return FALSE; }
712 
713  /** Set X axis alignment.
714  @param align alignment (choose between mpALIGN_BORDER_BOTTOM, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpALIGN_BORDER_TOP */
715  void SetAlign(int align) { m_flags = align; };
716 
717  /** Set X axis ticks or grid
718  @param ticks TRUE to plot axis ticks, FALSE to plot grid. */
719  void SetTicks(bool ticks) { m_ticks = ticks; };
720 
721  /** Get X axis ticks or grid
722  @return TRUE if plot is drawing axis ticks, FALSE if the grid is active. */
723  bool GetTicks() { return m_ticks; };
724 
725  /** Get X axis label view mode.
726  @return mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */
727  unsigned int GetLabelMode() { return m_labelType; };
728 
729  /** Set X axis label view mode.
730  @param mode mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */
731  void SetLabelMode(unsigned int mode) { m_labelType = mode; };
732 
733  /** Set X axis Label format (used for mpX_NORMAL draw mode).
734  @param format The format string */
735  void SetLabelFormat(const wxString& format) { m_labelFormat = format; };
736 
737  /** Get X axis Label format (used for mpX_NORMAL draw mode).
738  @return The format string */
739  const wxString& SetLabelFormat() { return m_labelFormat; };
740 
741 protected:
742  int m_flags; //!< Flag for axis alignment
743  bool m_ticks; //!< Flag to toggle between ticks or grid
744  unsigned int m_labelType; //!< Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds
745  wxString m_labelFormat; //!< Format string used to print labels
746 
747  DECLARE_DYNAMIC_CLASS(mpScaleX)
748 };
749 
750 /** Plot layer implementing a y-scale ruler.
751  If align is set to mpALIGN_CENTER, the ruler is fixed at X=0 in the coordinate system. If the align is set to mpALIGN_TOP or mpALIGN_BOTTOM, the axis is always drawn respectively at top or bottom of the window. A label is plotted at
752  the top-right hand of the ruler. The scale numbering automatically
753  adjusts to view and zoom factor.
754 */
756 {
757 public:
758  /** @param name Label to plot by the ruler
759  @param flags Set position of the scale respect to the window.
760  @param ticks Select ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid */
761  mpScaleY(wxString name = wxT("Y"), int flags = mpALIGN_CENTER, bool ticks = true);
762 
763  /** Layer plot handler.
764  This implementation will plot the ruler adjusted to the visible area.
765  */
766  virtual void Plot(wxDC & dc, mpWindow & w);
767 
768  /** Check whether this layer has a bounding box.
769  This implementation returns \a FALSE thus making the ruler invisible
770  to the plot layer bounding box calculation by mpWindow.
771  */
772  virtual bool HasBBox() { return FALSE; }
773 
774  /** Set Y axis alignment.
775  @param align alignment (choose between mpALIGN_BORDER_LEFT, mpALIGN_LEFT, mpALIGN_CENTER, mpALIGN_RIGHT, mpALIGN_BORDER_RIGHT) */
776  void SetAlign(int align) { m_flags = align; };
777 
778  /** Set Y axis ticks or grid
779  @param ticks TRUE to plot axis ticks, FALSE to plot grid. */
780  void SetTicks(bool ticks) { m_ticks = ticks; };
781 
782  /** Get Y axis ticks or grid
783  @return TRUE if plot is drawing axis ticks, FALSE if the grid is active. */
784  bool GetTicks() { return m_ticks; };
785 
786  /** Set Y axis Label format.
787  @param format The format string */
788  void SetLabelFormat(const wxString& format) { m_labelFormat = format; };
789 
790  /** Get Y axis Label format.
791  @return The format string */
792  const wxString& SetLabelFormat() { return m_labelFormat; };
793 
794 protected:
795  int m_flags; //!< Flag for axis alignment
796  bool m_ticks; //!< Flag to toggle between ticks or grid
797  wxString m_labelFormat; //!< Format string used to print labels
798 
799  DECLARE_DYNAMIC_CLASS(mpScaleY)
800 };
801 
802 //-----------------------------------------------------------------------------
803 // mpWindow
804 //-----------------------------------------------------------------------------
805 
806 /** @name Constants defining mouse modes for mpWindow
807 @{*/
808 
809 /** Mouse panning drags the view. Mouse mode for mpWindow. */
810 #define mpMOUSEMODE_DRAG 0
811 /** Mouse panning creates a zoom box. Mouse mode for mpWindow. */
812 #define mpMOUSEMODE_ZOOMBOX 1
813 
814 /*@}*/
815 /** Define the type for the list of layers inside mpWindow */
816 //WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, wxLayerList );
817 typedef std::deque<mpLayer*> wxLayerList;
818 
819 /** Canvas for plotting mpLayer implementations.
820 
821  This class defines a zoomable and moveable 2D plot canvas. Any number
822  of mpLayer implementations (scale rulers, function plots, ...) can be
823  attached using mpWindow::AddLayer.
824 
825  The canvas window provides a context menu with actions for navigating the view.
826  The context menu can be retrieved with mpWindow::GetPopupMenu, e.g. for extending it
827  externally.
828 
829  Since wxMathPlot version 0.03, the mpWindow incorporates the following features:
830  - DoubleBuffering (Default=disabled): Can be set with EnableDoubleBuffer
831  - Mouse based pan/zoom (Default=enabled): Can be set with EnableMousePanZoom.
832 
833  The mouse commands can be visualized by the user through the popup menu, and are:
834  - Mouse Move+CTRL: Pan (Move)
835  - Mouse Wheel: Vertical scroll
836  - Mouse Wheel+SHIFT: Horizontal scroll
837  - Mouse Wheel UP+CTRL: Zoom in
838  - Mouse Wheel DOWN+CTRL: Zoom out
839 
840 */
841 class WXDLLIMPEXP_MATHPLOT mpWindow : public wxWindow
842 {
843 public:
844  mpWindow() {}
845  mpWindow( wxWindow *parent, wxWindowID id,
846  const wxPoint &pos = wxDefaultPosition,
847  const wxSize &size = wxDefaultSize,
848  long flags = 0);
849  ~mpWindow();
850 
851  /** Get reference to context menu of the plot canvas.
852  @return Pointer to menu. The menu can be modified.
853  */
854  wxMenu* GetPopupMenu() { return &m_popmenu; }
855 
856  /** Add a plot layer to the canvas.
857  @param layer Pointer to layer. The mpLayer object will get under control of mpWindow,
858  i.e. it will be delete'd on mpWindow destruction
859  @param refreshDisplay States whether to refresh the display (UpdateAll) after adding the layer.
860  @retval TRUE Success
861  @retval FALSE Failure due to out of memory.
862  */
863  bool AddLayer( mpLayer* layer, bool refreshDisplay = true);
864 
865  /** Remove a plot layer from the canvas.
866  @param layer Pointer to layer. The mpLayer object will be destructed using delete.
867  @param alsoDeleteObject If set to true, the mpLayer object will be also "deleted", not just removed from the internal list.
868  @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the layer.
869  @return true if layer is deleted correctly
870 
871  N.B. Only the layer reference in the mpWindow is deleted, the layer object still exists!
872  */
873  bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true);
874 
875  /** Remove all layers from the plot.
876  @param alsoDeleteObject If set to true, the mpLayer objects will be also "deleted", not just removed from the internal list.
877  @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the layers.
878  */
879  void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true);
880 
881 
882  /*! Get the layer in list position indicated.
883  N.B. You <i>must</i> know the index of the layer inside the list!
884  @param position position of the layer in the layers list
885  @return pointer to mpLayer
886  */
887  mpLayer* GetLayer(int position);
888 
889  /*! Get the layer by its name (case sensitive).
890  @param name The name of the layer to retrieve
891  @return A pointer to the mpLayer object, or NULL if not found.
892  */
893  mpLayer* GetLayerByName( const wxString &name);
894 
895  /** Get current view's X scale.
896  See @ref mpLayer::Plot "rules for coordinate transformation"
897  @return Scale
898  */
899  double GetXscl() { return m_scaleX; }
900  double GetScaleX(void) const{ return m_scaleX; }; // Schaling's method: maybe another method esists with the same name
901 
902  /** Get current view's Y scale.
903  See @ref mpLayer::Plot "rules for coordinate transformation"
904  @return Scale
905  */
906  double GetYscl() const { return m_scaleY; }
907  double GetScaleY(void) const { return m_scaleY; } // Schaling's method: maybe another method exists with the same name
908 
909  /** Get current view's X position.
910  See @ref mpLayer::Plot "rules for coordinate transformation"
911  @return X Position in layer coordinate system, that corresponds to the center point of the view.
912  */
913  double GetXpos() const { return m_posX; }
914  double GetPosX(void) const { return m_posX; }
915 
916  /** Get current view's Y position.
917  See @ref mpLayer::Plot "rules for coordinate transformation"
918  @return Y Position in layer coordinate system, that corresponds to the center point of the view.
919  */
920  double GetYpos() const { return m_posY; }
921  double GetPosY(void) const { return m_posY; }
922 
923  /** Get current view's X dimension in device context units.
924  Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
925  implementations should rely on the value returned by the function.
926  See @ref mpLayer::Plot "rules for coordinate transformation"
927  @return X dimension.
928  */
929  int GetScrX(void) const { return m_scrX; }
930  int GetXScreen(void) const { return m_scrX; }
931 
932  /** Get current view's Y dimension in device context units.
933  Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
934  implementations should rely on the value returned by the function.
935  See @ref mpLayer::Plot "rules for coordinate transformation"
936  @return Y dimension.
937  */
938  int GetScrY(void) const { return m_scrY; }
939  int GetYScreen(void) const { return m_scrY; }
940 
941  /** Set current view's X scale and refresh display.
942  @param scaleX New scale, must not be 0.
943  */
944  void SetScaleX(double scaleX);
945 
946  /** Set current view's Y scale and refresh display.
947  @param scaleY New scale, must not be 0.
948  */
949  void SetScaleY(double scaleY) { if (scaleY!=0) m_scaleY=scaleY; UpdateAll(); }
950 
951  /** Set current view's X position and refresh display.
952  @param posX New position that corresponds to the center point of the view.
953  */
954  void SetPosX(double posX) { m_posX=posX; UpdateAll(); }
955 
956  /** Set current view's Y position and refresh display.
957  @param posY New position that corresponds to the center point of the view.
958  */
959  void SetPosY(double posY) { m_posY=posY; UpdateAll(); }
960 
961  /** Set current view's X and Y position and refresh display.
962  @param posX New position that corresponds to the center point of the view.
963  @param posY New position that corresponds to the center point of the view.
964  */
965  void SetPos( double posX, double posY) { m_posX=posX; m_posY=posY; UpdateAll(); }
966 
967  /** Set current view's dimensions in device context units.
968  Needed by plotting functions. It doesn't refresh display.
969  @param scrX New position that corresponds to the center point of the view.
970  @param scrY New position that corresponds to the center point of the view.
971  */
972  void SetScr( int scrX, int scrY) { m_scrX=scrX; m_scrY=scrY; }
973 
974  /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
975  * @sa p2y,x2p,y2p */
976 // double p2x(wxCoord pixelCoordX, bool drawOutside = true ); // { return m_posX + pixelCoordX/m_scaleX; }
977  inline double p2x(wxCoord pixelCoordX ) { return m_posX + pixelCoordX/m_scaleX; }
978 
979  /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
980  * @sa p2x,x2p,y2p */
981 // double p2y(wxCoord pixelCoordY, bool drawOutside = true ); //{ return m_posY - pixelCoordY/m_scaleY; }
982  inline double p2y(wxCoord pixelCoordY ) { return m_posY - pixelCoordY/m_scaleY; }
983 
984  /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
985  * @sa p2x,p2y,y2p */
986 // wxCoord x2p(double x, bool drawOutside = true); // { return (wxCoord) ( (x-m_posX) * m_scaleX); }
987  inline wxCoord x2p(double x) { return (wxCoord) ( (x-m_posX) * m_scaleX); }
988 
989  /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
990  * @sa p2x,p2y,x2p */
991 // wxCoord y2p(double y, bool drawOutside = true); // { return (wxCoord) ( (m_posY-y) * m_scaleY); }
992  inline wxCoord y2p(double y) { return (wxCoord) ( (m_posY-y) * m_scaleY); }
993 
994 
995  /** Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
996  */
997  void EnableDoubleBuffer( bool enabled ) { m_enableDoubleBuffer = enabled; }
998 
999  /** Enable/disable the feature of pan/zoom with the mouse (default=enabled)
1000  */
1001  void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
1002 
1003  /** Enable or disable X/Y scale aspect locking for the view.
1004  @note Explicit calls to mpWindow::SetScaleX and mpWindow::SetScaleY will set
1005  an unlocked aspect, but any other action changing the view scale will
1006  lock the aspect again.
1007  */
1008  void LockAspect(bool enable = TRUE);
1009 
1010  /** Checks whether the X/Y scale aspect is locked.
1011  @retval TRUE Locked
1012  @retval FALSE Unlocked
1013  */
1014  inline bool IsAspectLocked() { return m_lockaspect; }
1015 
1016  /** Set view to fit global bounding box of all plot layers and refresh display.
1017  Scale and position will be set to show all attached mpLayers.
1018  The X/Y scale aspect lock is taken into account.
1019  */
1020  void Fit();
1021 
1022  /** Set view to fit a given bounding box and refresh display.
1023  The X/Y scale aspect lock is taken into account.
1024  If provided, the parameters printSizeX and printSizeY are taken as the DC size, and the
1025  pixel scales are computed accordingly. Also, in this case the passed borders are not saved
1026  as the "desired borders", since this use will be invoked only when printing.
1027  */
1028  void Fit(double xMin, double xMax, double yMin, double yMax,wxCoord *printSizeX=NULL,wxCoord *printSizeY=NULL);
1029 
1030  /** Zoom into current view and refresh display
1031  * @param centerPoint The point (pixel coordinates) that will stay in the same position on the screen after the zoom (by default, the center of the mpWindow).
1032  */
1033  void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
1034 
1035  /** Zoom out current view and refresh display
1036  * @param centerPoint The point (pixel coordinates) that will stay in the same position on the screen after the zoom (by default, the center of the mpWindow).
1037  */
1038  void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
1039 
1040  /** Zoom in current view along X and refresh display */
1041  void ZoomInX();
1042  /** Zoom out current view along X and refresh display */
1043  void ZoomOutX();
1044  /** Zoom in current view along Y and refresh display */
1045  void ZoomInY();
1046  /** Zoom out current view along Y and refresh display */
1047  void ZoomOutY();
1048 
1049  /** Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order) */
1050  void ZoomRect(wxPoint p0, wxPoint p1);
1051 
1052  /** Refresh display */
1053  void UpdateAll();
1054 
1055  // Added methods by Davide Rondini
1056 
1057  /** Counts the number of plot layers, excluding axes or text: this is to count only the layers which have a bounding box.
1058  \return The number of profiles plotted.
1059  */
1060  unsigned int CountLayers();
1061 
1062  /** Counts the number of plot layers, whether or not they have a bounding box.
1063  \return The number of layers in the mpWindow. */
1064  size_t CountAllLayers() { return m_layers.size(); };
1065 
1066  /** Draws the mpWindow on a page for printing
1067  \param print the mpPrintout where to print the graph */
1068  //void PrintGraph(mpPrintout *print);
1069 
1071  {
1072  wxCommandEvent dum;
1073  OnPrintMenu(dum);
1074  }
1075 
1076 
1077  /** Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
1078  * @sa Fit
1079  */
1080  double GetDesiredXmin() {return m_desiredXmin; }
1081 
1082  /** Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
1083  * @sa Fit
1084  */
1085  double GetDesiredXmax() {return m_desiredXmax; }
1086 
1087  /** Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
1088  * @sa Fit
1089  */
1090  double GetDesiredYmin() {return m_desiredYmin; }
1091 
1092  /** Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
1093  * @sa Fit
1094  */
1095  double GetDesiredYmax() {return m_desiredYmax; }
1096 
1097  /** Returns the bounding box coordinates
1098  @param bbox Pointer to a 6-element double array where to store bounding box coordinates. */
1099  void GetBoundingBox(double* bbox);
1100 
1101  /** Enable/disable scrollbars
1102  @param status Set to true to show scrollbars */
1103  void SetMPScrollbars(bool status);
1104 
1105  /** Get scrollbars status.
1106  @return true if scrollbars are visible */
1107  bool GetMPScrollbars() {return m_enableScrollBars; };
1108 
1109  /** Draw the window on a wxBitmap, then save it to a file.
1110  @param filename File name where to save the screenshot
1111  @param type image type to be saved: see wxImage output file types for flags
1112  @param imageSize Set a size for the output image. Default is the same as the screen size
1113  @param fit Decide whether to fit the plot into the size*/
1114  bool SaveScreenshot(const wxString& filename, int type = wxBITMAP_TYPE_BMP, wxSize imageSize = wxDefaultSize, bool fit = false);
1115 
1116  /** This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse wheel.
1117  * It must be a number above unity. This number is used for zoom in, and its inverse for zoom out. Set to 1.5 by default. */
1118  static double zoomIncrementalFactor;
1119 
1120  /** Set window margins, creating a blank area where some kinds of layers cannot draw. This is useful for example to draw axes outside the area where the plots are drawn.
1121  @param top Top border
1122  @param right Right border
1123  @param bottom Bottom border
1124  @param left Left border */
1125  void SetMargins(int top, int right, int bottom, int left);
1126 
1127  /** Set the top margin. @param top Top Margin */
1128  void SetMarginTop(int top) { m_marginTop = top; };
1129  /** Set the right margin. @param right Right Margin */
1130  void SetMarginRight(int right) { m_marginRight = right; };
1131  /** Set the bottom margin. @param bottom Bottom Margin */
1132  void SetMarginBottom(int bottom) { m_marginBottom = bottom; };
1133  /** Set the left margin. @param left Left Margin */
1134  void SetMarginLeft(int left) { m_marginLeft = left; };
1135 
1136  /** Get the top margin. @param top Top Margin */
1137  int GetMarginTop() { return m_marginTop; };
1138  /** Get the right margin. @param right Right Margin */
1139  int GetMarginRight() { return m_marginRight; };
1140  /** Get the bottom margin. @param bottom Bottom Margin */
1141  int GetMarginBottom() { return m_marginBottom; };
1142  /** Get the left margin. @param left Left Margin */
1143  int GetMarginLeft() { return m_marginLeft; };
1144 
1145  /** Sets whether to show coordinate tooltip when mouse passes over the plot. \param value true for enable, false for disable */
1146  // void EnableCoordTooltip(bool value = true);
1147  /** Gets coordinate tooltip status. \return true for enable, false for disable */
1148  // bool GetCoordTooltip() { return m_coordTooltip; };
1149 
1150  /** Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.
1151  @param point The position to be checked
1152  @return If an info layer is found, returns its pointer, NULL otherwise */
1153  mpInfoLayer* IsInsideInfoLayer(wxPoint& point);
1154 
1155  /** Sets the visibility of a layer by its name.
1156  @param name The layer name to set visibility
1157  @param viewable the view status to be set */
1158  void SetLayerVisible(const wxString &name, bool viewable);
1159 
1160  /** Check whether a layer with given name is visible
1161  @param name The layer name
1162  @return layer visibility status */
1163  bool IsLayerVisible(const wxString &name );
1164 
1165  /** Sets the visibility of a layer by its position in layer list.
1166  @param position The layer position in layer list
1167  @param viewable the view status to be set */
1168  void SetLayerVisible(const unsigned int position, bool viewable);
1169 
1170  /** Check whether the layer at given position is visible
1171  @param position The layer position in layer list
1172  @return layer visibility status */
1173  bool IsLayerVisible(const unsigned int position );
1174 
1175  /** Set Color theme. Provide colours to set a new colour theme.
1176  @param bgColour Background colour
1177  @param drawColour The colour used to draw all elements in foreground, axes excluded
1178  @param axesColour The colour used to draw axes (but not their labels) */
1179  void SetColourTheme(const wxColour& bgColour, const wxColour& drawColour, const wxColour& axesColour);
1180 
1181  /** Get axes draw colour
1182  @return reference to axis colour used in theme */
1183  const wxColour& GetAxesColour() { return m_axColour; };
1184 
1185  /** Recalculate global layer bounding box, and save it in m_minX,...
1186  * \return true if there is any valid BBox information.
1187  */
1188  virtual bool UpdateBBox();
1189 
1190 protected:
1191  void OnPaint (wxPaintEvent &event); //!< Paint handler, will plot all attached layers
1192  void OnSize (wxSizeEvent &event); //!< Size handler, will update scroll bar sizes
1193  // void OnScroll2 (wxScrollWinEvent &event); //!< Scroll handler, will move canvas
1194  void OnShowPopupMenu (wxMouseEvent &event); //!< Mouse handler, will show context menu
1195  void OnMouseRightDown(wxMouseEvent &event); //!< Mouse handler, for detecting when the user drags with the right button or just "clicks" for the menu
1196  void OnCenter (wxCommandEvent &event); //!< Context menu handler
1197  void OnFit (wxCommandEvent &event); //!< Context menu handler
1198  void OnZoomIn (wxCommandEvent &event); //!< Context menu handler
1199  void OnZoomOut (wxCommandEvent &event); //!< Context menu handler
1200  void OnLockAspect (wxCommandEvent &event); //!< Context menu handler
1201  void OnMouseHelp (wxCommandEvent &event); //!< Context menu handler
1202  void OnPrintMenu (wxCommandEvent &event); //!< Context menu handler
1203  void OnMouseWheel (wxMouseEvent &event); //!< Mouse handler for the wheel
1204  void OnMouseMove (wxMouseEvent &event); //!< Mouse handler for mouse motion (for pan)
1205  void OnMouseLeftDown (wxMouseEvent &event); //!< Mouse left click (for rect zoom)
1206  void OnMouseLeftRelease (wxMouseEvent &event); //!< Mouse left click (for rect zoom)
1207  void OnScrollThumbTrack (wxScrollWinEvent &event); //!< Scroll thumb on scroll bar moving
1208  void OnScrollPageUp (wxScrollWinEvent &event); //!< Scroll page up
1209  void OnScrollPageDown (wxScrollWinEvent &event); //!< Scroll page down
1210  void OnScrollLineUp (wxScrollWinEvent &event); //!< Scroll line up
1211  void OnScrollLineDown (wxScrollWinEvent &event); //!< Scroll line down
1212  void OnScrollTop (wxScrollWinEvent &event); //!< Scroll to top
1213  void OnScrollBottom (wxScrollWinEvent &event); //!< Scroll to bottom
1214 
1215  void DoScrollCalc (const int position, const int orientation);
1216 
1217  void DoZoomInXCalc (const int staticXpixel);
1218  void DoZoomInYCalc (const int staticYpixel);
1219  void DoZoomOutXCalc (const int staticXpixel);
1220  void DoZoomOutYCalc (const int staticYpixel);
1221 
1222  //wxList m_layers; //!< List of attached plot layers
1223  wxLayerList m_layers; //!< List of attached plot layers
1224  wxMenu m_popmenu; //!< Canvas' context menu
1225  bool m_lockaspect;//!< Scale aspect is locked or not
1226  // bool m_coordTooltip; //!< Selects whether to show coordinate tooltip
1227  wxColour m_bgColour; //!< Background Colour
1228  wxColour m_fgColour; //!< Foreground Colour
1229  wxColour m_axColour; //!< Axes Colour
1230 
1231  double m_minX; //!< Global layer bounding box, left border incl.
1232  double m_maxX; //!< Global layer bounding box, right border incl.
1233  double m_minY; //!< Global layer bounding box, bottom border incl.
1234  double m_maxY; //!< Global layer bounding box, top border incl.
1235  double m_scaleX; //!< Current view's X scale
1236  double m_scaleY; //!< Current view's Y scale
1237  double m_posX; //!< Current view's X position
1238  double m_posY; //!< Current view's Y position
1239  int m_scrX; //!< Current view's X dimension
1240  int m_scrY; //!< Current view's Y dimension
1241  int m_clickedX; //!< Last mouse click X position, for centering and zooming the view
1242  int m_clickedY; //!< Last mouse click Y position, for centering and zooming the view
1243 
1244  /** These are updated in Fit() only, and may be different from the real borders (layer coordinates) only if lock aspect ratio is true.
1245  */
1246  double m_desiredXmin,m_desiredXmax,m_desiredYmin,m_desiredYmax;
1247 
1248  int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
1249 
1250  int m_last_lx,m_last_ly; //!< For double buffering
1251  wxMemoryDC m_buff_dc; //!< For double buffering
1252  wxBitmap *m_buff_bmp; //!< For double buffering
1253  bool m_enableDoubleBuffer; //!< For double buffering
1254  bool m_enableMouseNavigation; //!< For pan/zoom with the mouse.
1256  long m_mouseRClick_X,m_mouseRClick_Y; //!< For the right button "drag" feature
1257  int m_mouseLClick_X, m_mouseLClick_Y; //!< Starting coords for rectangular zoom selection
1259  int m_scrollX, m_scrollY;
1260  mpInfoLayer* m_movingInfoLayer; //!< For moving info layers over the window area
1261 
1262  DECLARE_DYNAMIC_CLASS(mpWindow)
1263  DECLARE_EVENT_TABLE()
1264 };
1265 
1266 //-----------------------------------------------------------------------------
1267 // mpFXYVector - provided by Jose Luis Blanco
1268 //-----------------------------------------------------------------------------
1269 
1270 /** A class providing graphs functionality for a 2D plot (either continuous or a set of points), from vectors of data.
1271  This class can be used directly, the user does not need to derive any new class. Simply pass the data as two vectors
1272  with the same length containing the X and Y coordinates to the method SetData.
1273 
1274  To generate a graph with a set of points, call
1275  \code
1276  layerVar->SetContinuity(false)
1277  \endcode
1278 
1279  or
1280 
1281  \code
1282  layerVar->SetContinuity(true)
1283  \endcode
1284 
1285  to render the sequence of coordinates as a continuous line.
1286 
1287  (Added: Jose Luis Blanco, AGO-2007)
1288 */
1290 {
1291 public:
1292  /** @param name Label
1293  @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
1294  */
1295  mpFXYVector(wxString name = wxEmptyString, int flags = mpALIGN_NE);
1296 
1297  /** Changes the internal data: the set of points to draw.
1298  Both vectors MUST be of the same length. This method DOES NOT refresh the mpWindow; do it manually.
1299  * @sa Clear
1300  */
1301  void SetData( const std::vector<double> &xs,const std::vector<double> &ys);
1302 
1303  /** Changes the internal data: the set of points to draw.
1304  Both vectors MUST be of the same length. This method DOES NOT refresh the mpWindow; do it manually.
1305  * @sa Clear
1306  */
1307  void SetData( const std::vector<float> &xs,const std::vector<float> &ys);
1308 
1309  /** Clears all the data, leaving the layer empty.
1310  * @sa SetData
1311  */
1312  void Clear();
1313 
1314  /** Returns the number of data points currently hold in X & Y.
1315  * @sa SetData
1316  */
1317  size_t GetDataLength() const
1318  {
1319  return m_xs.size();
1320  }
1321 
1322  /** Append a new data point (x,y)
1323  * @sa SetData
1324  */
1325  void AppendDataPoint(float x, float y);
1326 
1327 protected:
1328  /** The internal copy of the set of data to draw.
1329  */
1330  std::vector<double> m_xs,m_ys;
1331 
1332  /** The internal counter for the "GetNextXY" interface
1333  */
1334  size_t m_index;
1335 
1336  /** Loaded at SetData
1337  */
1338  double m_minX,m_maxX,m_minY,m_maxY;
1339 
1340  /** Rewind value enumeration with mpFXY::GetNextXY.
1341  Overridden in this implementation.
1342  */
1343  void Rewind();
1344 
1345  /** Get locus value for next N.
1346  Overridden in this implementation.
1347  @param x Returns X value
1348  @param y Returns Y value
1349  */
1350  bool GetNextXY(double & x, double & y);
1351 
1352 public:
1353  /** Returns the actual minimum X data (loaded in SetData).
1354  */
1355  double GetMinX() { return m_minX; }
1356 
1357  /** Returns the actual minimum Y data (loaded in SetData).
1358  */
1359  double GetMinY() { return m_minY; }
1360 
1361  /** Returns the actual maximum X data (loaded in SetData).
1362  */
1363  double GetMaxX() { return m_maxX; }
1364 
1365  /** Returns the actual maximum Y data (loaded in SetData).
1366  */
1367  double GetMaxY() { return m_maxY; }
1368 
1369 protected:
1370  int m_flags; //!< Holds label alignment
1371 
1372  DECLARE_DYNAMIC_CLASS(mpFXYVector)
1373 };
1374 
1375 //-----------------------------------------------------------------------------
1376 // mpText - provided by Val Greene
1377 //-----------------------------------------------------------------------------
1378 
1379 /** Plot layer implementing a text string.
1380 The text is plotted using a percentage system 0-100%, so the actual
1381 coordinates for the location are not required, and the text stays
1382 on the plot reguardless of the other layers location and scaling
1383 factors.
1384 */
1386 {
1387 public:
1388  /** @param name text to be drawn in the plot
1389  @param offsetx holds offset for the X location in percentage (0-100)
1390  @param offsety holds offset for the Y location in percentage (0-100) */
1391  mpText(wxString name = wxT("Title"), int offsetx = 5, int offsety = 50);
1392 
1393  /** Text Layer plot handler.
1394  This implementation will plot text adjusted to the visible area. */
1395  virtual void Plot(wxDC & dc, mpWindow & w);
1396 
1397  /** mpText should not be used for scaling decisions. */
1398  virtual bool HasBBox() { return FALSE; }
1399 
1400 protected:
1401  int m_offsetx; //!< Holds offset for X in percentage
1402  int m_offsety; //!< Holds offset for Y in percentage
1403 
1404  DECLARE_DYNAMIC_CLASS(mpText)
1405 };
1406 
1407 
1408 //-----------------------------------------------------------------------------
1409 // mpPrintout - provided by Davide Rondini
1410 //-----------------------------------------------------------------------------
1411 
1412 /** Printout class used by mpWindow to draw in the objects to be printed.
1413  The object itself can then used by the default wxWidgets printing system
1414  to print mppWindow objects.
1415 */
1416 class WXDLLIMPEXP_MATHPLOT mpPrintout : public wxPrintout
1417 {
1418 public:
1419  mpPrintout(mpWindow* drawWindow, const wxChar *title = _T("wxMathPlot print output"));
1420  virtual ~mpPrintout() {};
1421 
1422  void SetDrawState(bool drawState) {drawn = drawState;};
1423  bool OnPrintPage(int page);
1424  bool HasPage(int page);
1425 
1426 private:
1427  bool drawn;
1429 };
1430 
1431 
1432 //-----------------------------------------------------------------------------
1433 // mpMovableObject - provided by Jose Luis Blanco
1434 //-----------------------------------------------------------------------------
1435 /** This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
1436  * The current transformation is set through SetCoordinateBase.
1437  * To ease the implementation of descendent classes, mpMovableObject will
1438  * be in charge of Bounding Box computation and layer rendering, assuming that
1439  * the object updates its shape in m_shape_xs & m_shape_ys.
1440  */
1442 {
1443 public:
1444  /** Default constructor (sets location and rotation to (0,0,0))
1445  */
1447  m_reference_x(0),
1448  m_reference_y(0),
1449  m_reference_phi(0),
1450  m_shape_xs(0),
1451  m_shape_ys(0)
1452  {
1453  m_type = mpLAYER_PLOT;
1454  }
1455 
1456  virtual ~mpMovableObject() {};
1457 
1458  /** Get the current coordinate transformation.
1459  */
1460  void GetCoordinateBase( double &x, double &y, double &phi ) const
1461  {
1462  x = m_reference_x;
1463  y = m_reference_y;
1464  phi = m_reference_phi;
1465  }
1466 
1467  /** Set the coordinate transformation (phi in radians, 0 means no rotation).
1468  */
1469  void SetCoordinateBase( double x, double y, double phi = 0 )
1470  {
1471  m_reference_x = x;
1472  m_reference_y = y;
1473  m_reference_phi = phi;
1474  m_flags = mpALIGN_NE;
1475  ShapeUpdated();
1476  }
1477 
1478  virtual bool HasBBox() { return m_trans_shape_xs.size()!=0; }
1479 
1480  /** Get inclusive left border of bounding box.
1481  */
1482  virtual double GetMinX() { return m_bbox_min_x; }
1483 
1484  /** Get inclusive right border of bounding box.
1485  */
1486  virtual double GetMaxX() { return m_bbox_max_x; }
1487 
1488  /** Get inclusive bottom border of bounding box.
1489  */
1490  virtual double GetMinY() { return m_bbox_min_y; }
1491 
1492  /** Get inclusive top border of bounding box.
1493  */
1494  virtual double GetMaxY() { return m_bbox_max_y; }
1495 
1496  virtual void Plot(wxDC & dc, mpWindow & w);
1497 
1498  /** Set label axis alignment.
1499  * @param align alignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE
1500  */
1501  void SetAlign(int align) { m_flags = align; };
1502 
1503 protected:
1504  int m_flags; //!< Holds label alignment
1505 
1506  /** The coordinates of the object (orientation "phi" is in radians).
1507  */
1508  double m_reference_x,m_reference_y,m_reference_phi;
1509 
1510  /** A method for 2D translation and rotation, using the current transformation stored in m_reference_x,m_reference_y,m_reference_phi.
1511  */
1512  void TranslatePoint( double x,double y, double &out_x, double &out_y );
1513 
1514  /** This contains the object points, in local coordinates (to be transformed by the current transformation).
1515  */
1516  std::vector<double> m_shape_xs,m_shape_ys;
1517 
1518  /** The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh).
1519  *
1520  */
1521  std::vector<double> m_trans_shape_xs,m_trans_shape_ys;
1522 
1523  /** The precomputed bounding box:
1524  * @sa ShapeUpdated
1525  */
1526  double m_bbox_min_x,m_bbox_max_x,m_bbox_min_y,m_bbox_max_y;
1527 
1528  /** Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transformation changes.
1529  * This method updates the buffers m_trans_shape_xs/ys, and the precomputed bounding box.
1530  */
1531  void ShapeUpdated();
1532 
1533 };
1534 
1535 //-----------------------------------------------------------------------------
1536 // mpCovarianceEllipse - provided by Jose Luis Blanco
1537 //-----------------------------------------------------------------------------
1538 /** A 2D ellipse, described by a 2x2 covariance matrix.
1539  * The relation between the multivariate Gaussian confidence interval and
1540  * the "quantiles" in this class is:
1541  * - 1 : 68.27% confidence interval
1542  * - 2 : 95.45%
1543  * - 3 : 99.73%
1544  * - 4 : 99.994%
1545  * For example, see http://en.wikipedia.org/wiki/Normal_distribution#Standard_deviation_and_confidence_intervals
1546  *
1547  * The ellipse will be always centered at the origin. Use mpMovableObject::SetCoordinateBase to move it.
1548  */
1550 {
1551 public:
1552  /** Default constructor.
1553  * Initializes to a unity diagonal covariance matrix, a 95% confidence interval (2 sigmas), 32 segments, and a continuous plot (m_continuous=true).
1554  */
1556  double cov_00 = 1,
1557  double cov_11 = 1,
1558  double cov_01 = 0,
1559  double quantiles = 2,
1560  int segments = 32,
1561  const wxString & layerName = wxT("") ) :
1562  m_cov_00(cov_00),
1563  m_cov_11(cov_11),
1564  m_cov_01(cov_01),
1565  m_quantiles(quantiles),
1566  m_segments(segments)
1567  {
1568  m_continuous = true;
1569  m_name = layerName;
1570  RecalculateShape();
1571  m_type = mpLAYER_PLOT;
1572  }
1573 
1575 
1576  double GetQuantiles() const { return m_quantiles; }
1577 
1578  /** Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above).
1579  */
1580  void SetQuantiles(double q)
1581  {
1582  m_quantiles=q;
1583  RecalculateShape();
1584  }
1585 
1586  void SetSegments( int segments ) { m_segments = segments; }
1587  int GetSegments( ) const { return m_segments; }
1588 
1589  /** Returns the elements of the current covariance matrix:
1590  */
1591  void GetCovarianceMatrix( double &cov_00,double &cov_01,double &cov_11 ) const
1592  {
1593  cov_00 = m_cov_00;
1594  cov_01 = m_cov_01;
1595  cov_11 = m_cov_11;
1596  }
1597 
1598  /** Changes the covariance matrix:
1599  */
1600  void SetCovarianceMatrix( double cov_00,double cov_01,double cov_11 )
1601  {
1602  m_cov_00 = cov_00;
1603  m_cov_01 = cov_01;
1604  m_cov_11 = cov_11;
1605  RecalculateShape();
1606  }
1607 
1608 protected:
1609  /** The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
1610  */
1611  double m_cov_00,m_cov_11,m_cov_01;
1612  double m_quantiles;
1613 
1614  /** The number of line segments that build up the ellipse.
1615  */
1617 
1618  /** Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
1619  */
1620  void RecalculateShape();
1621 };
1622 
1623 //-----------------------------------------------------------------------------
1624 // mpPolygon - provided by Jose Luis Blanco
1625 //-----------------------------------------------------------------------------
1626 /** An arbitrary polygon, descendant of mpMovableObject.
1627  * Use "setPoints" to set the list of N points. This class also can draw non-closed polygons by
1628  * passing the appropriate parameters to "setPoints". To draw a point-cloud, call "SetContinuity(false)".
1629  */
1631 {
1632 public:
1633  /** Default constructor.
1634  */
1635  mpPolygon( const wxString & layerName = wxT("") )
1636  {
1637  m_continuous = true;
1638  m_name = layerName;
1639  }
1640 
1641  virtual ~mpPolygon() {}
1642 
1643  /** Set the points in the polygon.
1644  * @param points_xs The X coordinates of the points.
1645  * @param points_ys The Y coordinates of the points.
1646  * @param closedShape If set to true, an additional segment will be added from the last to the first point.
1647  */
1648  void setPoints(
1649  const std::vector<double>& points_xs,
1650  const std::vector<double>& points_ys,
1651  bool closedShape=true );
1652 
1653  /** Set the points in the polygon.
1654  * @param points_xs The X coordinates of the points.
1655  * @param points_ys The Y coordinates of the points.
1656  * @param closedShape If set to true, an additional segment will be added from the last to the first point.
1657  */
1658  void setPoints(
1659  const std::vector<float>& points_xs,
1660  const std::vector<float>& points_ys,
1661  bool closedShape=true );
1662 
1663 
1664 
1665 };
1666 
1667 //-----------------------------------------------------------------------------
1668 // mpMovableObject - provided by Jose Luis Blanco
1669 //-----------------------------------------------------------------------------
1670 /** This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
1671  * The current transformation is set through SetCoordinateBase.
1672  * To ease the implementation of descendent classes, mpMovableObject will
1673  * be in charge of Bounding Box computation and layer render, assuming that
1674  * the object updates its shape in m_shape_xs & m_shape_ys.
1675  */
1677 {
1678 public:
1679  /** Default constructor.
1680  */
1682  {
1683  m_min_x = m_max_x =
1684  m_min_y = m_max_y = 0;
1685  m_validImg = false;
1686  m_type = mpLAYER_BITMAP;
1687  }
1688 
1689  virtual ~mpBitmapLayer() {};
1690 
1691  /** Returns a copy of the current bitmap assigned to the layer.
1692  */
1693  void GetBitmapCopy( wxImage &outBmp ) const;
1694 
1695  /** Change the bitmap associated with the layer (to update the screen, refresh the mpWindow).
1696  * @param inBmp The bitmap to associate. A copy is made, thus it can be released after calling this.
1697  * @param x The left corner X coordinate (in plot units).
1698  * @param y The top corner Y coordinate (in plot units).
1699  * @param lx The width in plot units.
1700  * @param ly The height in plot units.
1701  */
1702  void SetBitmap( const wxImage &inBmp, double x, double y, double lx, double ly );
1703 
1704  virtual bool HasBBox() { return true; }
1705 
1706  /** Get inclusive left border of bounding box.
1707  */
1708  virtual double GetMinX() { return m_min_x; }
1709 
1710  /** Get inclusive right border of bounding box.
1711  */
1712  virtual double GetMaxX() { return m_max_x; }
1713 
1714  /** Get inclusive bottom border of bounding box.
1715  */
1716  virtual double GetMinY() { return m_min_y; }
1717 
1718  /** Get inclusive top border of bounding box.
1719  */
1720  virtual double GetMaxY() { return m_max_y; }
1721 
1722  virtual void Plot(wxDC & dc, mpWindow & w);
1723 
1724  /** Set label axis alignment.
1725  * @param align alignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE
1726  */
1727  void SetAlign(int align) { m_flags = align; };
1728 
1729 protected:
1730  int m_flags; //!< Holds label alignment
1731 
1732  /** The internal copy of the Bitmap:
1733  */
1734  wxImage m_bitmap;
1735  wxBitmap m_scaledBitmap;
1736  wxCoord m_scaledBitmap_offset_x,m_scaledBitmap_offset_y;
1737 
1738 
1740 
1741 
1742  /** The shape of the bitmap:
1743  */
1744  double m_min_x,m_max_x,m_min_y,m_max_y;
1745 
1746 
1747 };
1748 
1749 
1750 
1751 /*@}*/
1752 
1753 #if defined(_MSC_VER)
1754  #pragma warning(pop)
1755 #endif
1756 
1757 
1758 #endif // _MP_MATHPLOT_H_
void SetPos(double posX, double posY)
Set current view&#39;s X and Y position and refresh display.
Definition: mathplot.h:965
int m_offsety
Holds offset for Y in percentage.
Definition: mathplot.h:1402
int m_flags
Holds label alignment.
Definition: mathplot.h:1370
wxMemoryDC m_buff_dc
For double buffering.
Definition: mathplot.h:1251
double m_posY
Current view&#39;s Y position.
Definition: mathplot.h:1238
void SetAlign(int align)
Set Y axis alignment.
Definition: mathplot.h:776
class WXDLLIMPEXP_MATHPLOT mpWindow
Definition: mathplot.h:126
bool GetMPScrollbars()
Get scrollbars status.
Definition: mathplot.h:1107
int GetMarginRight()
Get the right margin.
Definition: mathplot.h:1139
bool m_showName
States whether the name of the layer must be shown (default is true).
Definition: mathplot.h:334
double m_minX
Global layer bounding box, left border incl.
Definition: mathplot.h:1231
int m_flags
Holds label alignment.
Definition: mathplot.h:632
Plot type layer.
Definition: mathplot.h:149
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:1720
bool IsVisible()
Checks whether the layer is visible or not.
Definition: mathplot.h:314
Zoom into view at clickposition / window center.
Definition: mathplot.h:134
double GetYscl() const
Get current view&#39;s Y scale.
Definition: mathplot.h:906
An arbitrary polygon, descendant of mpMovableObject.
Definition: mathplot.h:1630
virtual ~mpPrintout()
Definition: mathplot.h:1420
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:201
A class providing graphs functionality for a 2D plot (either continuous or a set of points)...
Definition: mathplot.h:1289
int m_clickedX
Last mouse click X position, for centering and zooming the view.
Definition: mathplot.h:1241
__mp_Layer_Type
Definition: mathplot.h:146
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
Definition: mathplot.h:1676
double GetMinX()
Returns the actual minimum X data (loaded in SetData).
Definition: mathplot.h:1355
bool m_ticks
Flag to toggle between ticks or grid.
Definition: mathplot.h:796
bool m_mouseMovedAfterRightClick
Definition: mathplot.h:1255
class WXDLLIMPEXP_MATHPLOT mpFXYVector
Definition: mathplot.h:123
Layer type undefined.
Definition: mathplot.h:147
virtual ~mpPolygon()
Definition: mathplot.h:1641
wxString m_name
Layer&#39;s name.
Definition: mathplot.h:332
double GetYpos() const
Get current view&#39;s Y position.
Definition: mathplot.h:920
wxString GetName() const
Get layer name.
Definition: mathplot.h:254
int m_offsetx
Holds offset for X in percentage.
Definition: mathplot.h:1401
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
double m_reference_y
Definition: mathplot.h:1508
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:772
double m_bbox_min_y
Definition: mathplot.h:1526
Canvas for plotting mpLayer implementations.
Definition: mathplot.h:841
void SetTicks(bool ticks)
Set X axis ticks or grid.
Definition: mathplot.h:719
double m_scaleY
Current view&#39;s Y scale.
Definition: mathplot.h:1236
std::vector< double > m_ys
Definition: mathplot.h:1330
void SetCoordinateBase(double x, double y, double phi=0)
Set the coordinate transformation (phi in radians, 0 means no rotation).
Definition: mathplot.h:1469
void SetAlign(int align)
Set label axis alignment.
Definition: mathplot.h:1727
JL: Prints the graph.
Definition: mathplot.h:139
mpPolygon(const wxString &layerName=wxT(""))
Default constructor.
Definition: mathplot.h:1635
int m_winY
Holds the mpWindow size. Used to rescale position when window is resized.
Definition: mathplot.h:413
int GetXScreen(void) const
Definition: mathplot.h:930
virtual ~mpBitmapLayer()
Definition: mathplot.h:1689
double GetScaleY(void) const
Definition: mathplot.h:907
Lock x/y scaling aspect.
Definition: mathplot.h:137
mpLayerType m_type
Define layer type, which is assigned by constructor.
Definition: mathplot.h:336
virtual bool HasBBox()
mpText should not be used for scaling decisions.
Definition: mathplot.h:1398
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:191
void SetDrawOutsideMargins(bool drawModeOutside)
Set Draw mode: inside or outside margins.
Definition: mathplot.h:297
int m_flags
Holds label alignment.
Definition: mathplot.h:561
bool drawn
Definition: mathplot.h:1427
double GetXscl()
Get current view&#39;s X scale.
Definition: mathplot.h:899
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:493
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:1490
const wxBrush & GetBrush() const
Get brush set for this layer.
Definition: mathplot.h:322
void SetMarginRight(int right)
Set the right margin.
Definition: mathplot.h:1130
double GetDesiredXmin()
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
Definition: mathplot.h:1080
wxMenu m_popmenu
Canvas&#39; context menu.
Definition: mathplot.h:1224
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:571
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
Definition: mathplot.h:604
wxColour m_axColour
Axes Colour.
Definition: mathplot.h:1229
wxBrush m_brush
The brush to be used for the background.
Definition: mathplot.h:412
bool m_visible
Toggles layer visibility.
Definition: mathplot.h:337
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Definition: mathplot.h:452
Plot layer implementing a x-scale ruler.
Definition: mathplot.h:694
size_t CountAllLayers()
Counts the number of plot layers, whether or not they have a bounding box.
Definition: mathplot.h:1064
int GetMarginLeft()
Get the left margin.
Definition: mathplot.h:1143
Shows information about the mouse commands.
Definition: mathplot.h:138
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:982
virtual void Plot(wxDC &dc, mpWindow &w)=0
Plot given view of layer to the given device context.
void SetPosX(double posX)
Set current view&#39;s X position and refresh display.
Definition: mathplot.h:954
int m_mouseLClick_Y
Starting coords for rectangular zoom selection.
Definition: mathplot.h:1257
Axis type layer.
Definition: mathplot.h:148
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:1708
mpInfoLayer * m_movingInfoLayer
For moving info layers over the window area.
Definition: mathplot.h:1260
std::deque< mpLayer * > wxLayerList
Define the type for the list of layers inside mpWindow.
Definition: mathplot.h:817
virtual bool IsInfo()
Specifies that this is an Info box layer.
Definition: mathplot.h:383
std::vector< double > m_trans_shape_ys
Definition: mathplot.h:1521
void GetCoordinateBase(double &x, double &y, double &phi) const
Get the current coordinate transformation.
Definition: mathplot.h:1460
void SetDrawState(bool drawState)
Definition: mathplot.h:1422
bool GetTicks()
Get Y axis ticks or grid.
Definition: mathplot.h:784
void EnableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
Definition: mathplot.h:1001
wxImage m_bitmap
The internal copy of the Bitmap:
Definition: mathplot.h:1734
int m_flags
Holds label alignment.
Definition: mathplot.h:675
const wxString & SetLabelFormat()
Get Y axis Label format.
Definition: mathplot.h:792
void SetAlign(int align)
Set X axis alignment.
Definition: mathplot.h:715
#define mpX_NORMAL
Set label for X axis in normal mode.
Definition: mathplot.h:507
size_t m_index
The internal counter for the "GetNextXY" interface.
Definition: mathplot.h:1334
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:1712
void SetCovarianceMatrix(double cov_00, double cov_01, double cov_11)
Changes the covariance matrix:
Definition: mathplot.h:1600
#define WXDLLIMPEXP_MATHPLOT
Definition: mathplot.h:77
Printout class used by mpWindow to draw in the objects to be printed.
Definition: mathplot.h:1416
int m_last_ly
For double buffering.
Definition: mathplot.h:1250
wxRect m_dim
The bounding rectangle of the box. It may be resized dynamically by the Plot method.
Definition: mathplot.h:407
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:992
int m_flags
Holds label alignment.
Definition: mathplot.h:593
wxBitmap * m_buff_bmp
For double buffering.
Definition: mathplot.h:1252
int GetScrX(void) const
Get current view&#39;s X dimension in device context units.
Definition: mathplot.h:929
Zoom out.
Definition: mathplot.h:135
void SetBrush(wxBrush brush)
Set layer brush.
Definition: mathplot.h:326
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
Definition: mathplot.h:1441
const wxPen & GetPen() const
Get pen set for this layer.
Definition: mathplot.h:264
double m_scaleX
Current view&#39;s X scale.
Definition: mathplot.h:1235
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:977
void GetCovarianceMatrix(double &cov_00, double &cov_01, double &cov_11) const
Returns the elements of the current covariance matrix:
Definition: mathplot.h:1591
void ShowPrintDialog()
Draws the mpWindow on a page for printing.
Definition: mathplot.h:1070
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
Definition: mathplot.h:997
wxLayerList m_layers
List of attached plot layers.
Definition: mathplot.h:1223
void SetFont(wxFont &font)
Set layer font.
Definition: mathplot.h:288
unsigned int m_labelType
Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.
Definition: mathplot.h:744
mpWindow * plotWindow
Definition: mathplot.h:1428
double m_minY
Global layer bounding box, bottom border incl.
Definition: mathplot.h:1233
class WXDLLIMPEXP_MATHPLOT mpScaleY
Definition: mathplot.h:125
class WXDLLIMPEXP_MATHPLOT mpLayer
Definition: mathplot.h:119
wxPen m_pen
Layer&#39;s pen.
Definition: mathplot.h:330
double GetXpos() const
Get current view&#39;s X position.
Definition: mathplot.h:913
#define mpALIGN_TOP
Aligns label to the top.
Definition: mathplot.h:499
wxString m_content
string holding the coordinates to be drawn.
Definition: mathplot.h:446
double m_desiredYmin
Definition: mathplot.h:1246
void SetMarginBottom(int bottom)
Set the bottom margin.
Definition: mathplot.h:1132
wxString m_labelFormat
Format string used to print labels.
Definition: mathplot.h:745
virtual double GetMinY()
Get inclusive bottom border of bounding box.
Definition: mathplot.h:1716
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:521
long m_mouseRClick_Y
For the right button "drag" feature.
Definition: mathplot.h:1256
void SetScaleY(double scaleY)
Set current view&#39;s Y scale and refresh display.
Definition: mathplot.h:949
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
Definition: mathplot.h:350
size_t GetDataLength() const
Returns the number of data points currently hold in X & Y.
Definition: mathplot.h:1317
double GetPosX(void) const
Definition: mathplot.h:914
bool IsAspectLocked()
Checks whether the X/Y scale aspect is locked.
Definition: mathplot.h:1014
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:178
bool GetContinuity() const
Gets the &#39;continuity&#39; property of the layer.
Definition: mathplot.h:274
void SetLabelFormat(const wxString &format)
Set X axis Label format (used for mpX_NORMAL draw mode).
Definition: mathplot.h:735
virtual bool HasBBox()
mpInfoLayer has not bounding box.
Definition: mathplot.h:372
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
Definition: mathplot.h:278
Implements an overlay box which shows the mouse coordinates in plot units.
Definition: mathplot.h:421
void SetContinuity(bool continuity)
Set the &#39;continuity&#39; property of the layer (true:draws a continuous line, false:draws separate points...
Definition: mathplot.h:269
int m_scrY
Current view&#39;s Y dimension.
Definition: mathplot.h:1240
void SetName(wxString name)
Set layer name.
Definition: mathplot.h:283
double GetMaxX()
Returns the actual maximum X data (loaded in SetData).
Definition: mathplot.h:1363
const wxString & SetLabelFormat()
Get X axis Label format (used for mpX_NORMAL draw mode).
Definition: mathplot.h:739
wxColour m_bgColour
Background Colour.
Definition: mathplot.h:1227
int GetMarginBottom()
Get the bottom margin.
Definition: mathplot.h:1141
bool m_enableDoubleBuffer
For double buffering.
Definition: mathplot.h:1253
Abstract base class providing plot and labeling functionality for functions F:X->Y.
Definition: mathplot.h:539
double GetDesiredYmin()
Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not ex...
Definition: mathplot.h:1090
Plot layer implementing a y-scale ruler.
Definition: mathplot.h:755
bool m_validImg
Definition: mathplot.h:1739
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:1478
virtual void Plot(wxDC &dc, mpWindow &w)
Plot method.
bool m_drawOutsideMargins
select if the layer should draw only inside margins or over all DC
Definition: mathplot.h:335
size_t size(const MATRIXLIKE &m, int dim)
Definition: bits.h:43
mpWindow()
Definition: mathplot.h:844
bool GetDrawOutsideMargins()
Get Draw mode: inside or outside margins.
Definition: mathplot.h:301
mpCovarianceEllipse(double cov_00=1, double cov_11=1, double cov_01=0, double quantiles=2, int segments=32, const wxString &layerName=wxT(""))
Default constructor.
Definition: mathplot.h:1555
unsigned int GetLabelMode()
Get X axis label view mode.
Definition: mathplot.h:727
double GetDesiredXmax()
Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
Definition: mathplot.h:1085
wxBitmap m_scaledBitmap
Definition: mathplot.h:1735
bool m_continuous
Specify if the layer will be plotted as a continuous line or a set of points.
Definition: mathplot.h:333
bool m_lockaspect
Scale aspect is locked or not.
Definition: mathplot.h:1225
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1616
bool m_enableScrollBars
Definition: mathplot.h:1258
enum __mp_Layer_Type mpLayerType
mpLayerType GetLayerType()
Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.
Definition: mathplot.h:310
class WXDLLIMPEXP_MATHPLOT mpFXY
Definition: mathplot.h:122
wxString m_labelFormat
Format string used to print labels.
Definition: mathplot.h:797
void SetPosY(double posY)
Set current view&#39;s Y position and refresh display.
Definition: mathplot.h:959
Fit view to match bounding box of all layers.
Definition: mathplot.h:133
class WXDLLIMPEXP_MATHPLOT mpPrintout
Definition: mathplot.h:128
virtual ~mpMovableObject()
Definition: mathplot.h:1456
A 2D ellipse, described by a 2x2 covariance matrix.
Definition: mathplot.h:1549
double GetQuantiles() const
Definition: mathplot.h:1576
class WXDLLIMPEXP_MATHPLOT mpFX
Definition: mathplot.h:120
double m_minY
Definition: mathplot.h:1338
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:1118
int GetMarginTop()
Get the top margin.
Definition: mathplot.h:1137
bool m_enableMouseNavigation
For pan/zoom with the mouse.
Definition: mathplot.h:1254
Bitmap type layer.
Definition: mathplot.h:151
virtual ~mpCovarianceEllipse()
Definition: mathplot.h:1574
void SetScr(int scrX, int scrY)
Set current view&#39;s dimensions in device context units.
Definition: mathplot.h:972
void SetLabelFormat(const wxString &format)
Set Y axis Label format.
Definition: mathplot.h:788
double GetMinY()
Returns the actual minimum Y data (loaded in SetData).
Definition: mathplot.h:1359
bool m_ticks
Flag to toggle between ticks or grid.
Definition: mathplot.h:743
virtual void UpdateInfo(mpWindow &w, wxEvent &event)
Updates the content of the info box.
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:495
mpMovableObject()
Default constructor (sets location and rotation to (0,0,0))
Definition: mathplot.h:1446
Info box type layer.
Definition: mathplot.h:150
const wxFont & GetFont() const
Get font set for this layer.
Definition: mathplot.h:259
double m_maxX
Global layer bounding box, right border incl.
Definition: mathplot.h:1232
double GetDesiredYmax()
Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exact...
Definition: mathplot.h:1095
wxCoord m_scaledBitmap_offset_y
Definition: mathplot.h:1736
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:206
Plot layer implementing a text string.
Definition: mathplot.h:1385
const wxColour & GetAxesColour()
Get axes draw colour.
Definition: mathplot.h:1183
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:1704
virtual double GetMaxY()
Get inclusive top border of bounding box.
Definition: mathplot.h:1494
wxBrush m_brush
Layer&#39;s brush.
Definition: mathplot.h:331
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:196
wxPoint m_reference
Holds the reference point for movements.
Definition: mathplot.h:411
void SetMarginTop(int top)
Set the top margin.
Definition: mathplot.h:1128
wxColour m_fgColour
Foreground Colour.
Definition: mathplot.h:1228
wxCoord minDrawY
Definition: mathplot.h:635
int GetYScreen(void) const
Definition: mathplot.h:939
void SetPen(wxPen pen)
Set layer pen.
Definition: mathplot.h:293
void SetQuantiles(double q)
Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above)...
Definition: mathplot.h:1580
void SetSegments(int segments)
Definition: mathplot.h:1586
void SetLabelMode(unsigned int mode)
Set X axis label view mode.
Definition: mathplot.h:731
Center view on click position.
Definition: mathplot.h:136
int GetScrY(void) const
Get current view&#39;s Y dimension in device context units.
Definition: mathplot.h:938
int m_clickedY
Last mouse click Y position, for centering and zooming the view.
Definition: mathplot.h:1242
double GetMaxY()
Returns the actual maximum Y data (loaded in SetData).
Definition: mathplot.h:1367
virtual double GetMinX()
Get inclusive left border of bounding box.
Definition: mathplot.h:1482
Plot layer, abstract base class.
Definition: mathplot.h:164
std::vector< double > m_shape_ys
Definition: mathplot.h:1516
int m_scrollY
Definition: mathplot.h:1259
class WXDLLIMPEXP_MATHPLOT mpScaleX
Definition: mathplot.h:124
double m_maxY
Global layer bounding box, top border incl.
Definition: mathplot.h:1234
class WXDLLIMPEXP_MATHPLOT mpFY
Definition: mathplot.h:121
class WXDLLIMPEXP_MATHPLOT mpText
Definition: mathplot.h:127
void SetTicks(bool ticks)
Set Y axis ticks or grid.
Definition: mathplot.h:780
double m_posX
Current view&#39;s X position.
Definition: mathplot.h:1237
int m_scrX
Current view&#39;s X dimension.
Definition: mathplot.h:1239
void SetAlign(int align)
Set label axis alignment.
Definition: mathplot.h:1501
bool GetTicks()
Get X axis ticks or grid.
Definition: mathplot.h:723
void SetMarginLeft(int left)
Set the left margin.
Definition: mathplot.h:1134
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:987
int m_marginTop
Definition: mathplot.h:1248
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:653
int GetSegments() const
Definition: mathplot.h:1587
virtual ~mpLayer()
Definition: mathplot.h:169
virtual bool IsInfo()
Check whether the layer is an info box.
Definition: mathplot.h:186
virtual double GetMaxX()
Get inclusive right border of bounding box.
Definition: mathplot.h:1486
void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:318
double GetPosY(void) const
Definition: mathplot.h:921
double m_min_y
Definition: mathplot.h:1744
virtual bool HasBBox()
Check whether this layer has a bounding box.
Definition: mathplot.h:711
mpBitmapLayer()
Default constructor.
Definition: mathplot.h:1681
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
Definition: mathplot.h:854
double GetScaleX(void) const
Definition: mathplot.h:900



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN: at Sun Aug 14 23:58:29 UTC 2016