Main MRPT website > C++ reference
MRPT logo

mathplot.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 // Name:            mathplot.cpp
00003 // Purpose:         Framework for plotting in wxWindows
00004 // Original Author: David Schalig
00005 // Maintainer:      Davide Rondini
00006 // Contributors:    Jose Luis Blanco, Val Greene
00007 // Created:         21/07/2003
00008 // Last edit:       22/02/2009
00009 // Copyright:       (c) David Schalig, Davide Rondini
00010 // Licence:         wxWindows licence
00011 /////////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef _MP_MATHPLOT_H_
00014 #define _MP_MATHPLOT_H_
00015 
00016 // JL: This is VERY ugly, but ask MS why we cannot export a DLL class with STL members !!
00017 #if defined(_MSC_VER)
00018         #pragma warning(push)
00019         #pragma warning(disable:4251)
00020 #endif
00021 
00022 /** @file mathplot.h */
00023 /** @mainpage wxMathPlot
00024     wxMathPlot is a framework for mathematical graph plotting in wxWindows.
00025 
00026     The framework is designed for convenience and ease of use.
00027 
00028     @section screenshots Screenshots
00029     <a href="http://wxmathplot.sourceforge.net/screenshot.shtml">Go to the screenshots page.</a>
00030 
00031     @section overview Overview
00032     The heart of wxMathPlot is mpWindow, which is a 2D canvas for plot layers.
00033     mpWindow can be embedded as subwindow in a wxPane, a wxFrame, or any other wxWindow.
00034     mpWindow provides a zoomable and moveable view of the layers. The current view can
00035     be controlled with the mouse, the scrollbars, and a context menu.
00036 
00037     Plot layers are implementations of the abstract base class mpLayer. Those can
00038     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.
00039     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.
00040 
00041     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.
00042 
00043     @section coding Coding conventions
00044     wxMathPlot sticks to wxWindow's coding conventions. All entities defined by wxMathPlot have the prefix <i>mp</i>.
00045 
00046     @section author Author and license
00047     wxMathPlot is published under the terms of the wxWindow license.<br>
00048     The original author is David Schalig <mrhill@users.sourceforge.net>.<br>
00049     From June 2007 the project is maintained by Davide Rondini <cdron77@users.sourceforge.net>.<br>
00050     Authors can be contacted via the wxMathPlot's homepage at
00051     https://sourceforge.net/projects/wxmathplot<br>
00052     Contributors:<br>
00053     Jose Luis Blanco, Val Greene.<br>
00054 */
00055 
00056 //this definition uses windows dll to export function.
00057 //WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
00058 //mathplot_EXPORTS will be defined by cmake
00059 //#ifdef mathplot_EXPORTS
00060 // #define WXDLLIMPEXP_MATHPLOT WXEXPORT
00061 // #define WXDLLIMPEXP_DATA_MATHPLOT(type) WXEXPORT type
00062 //#else // not making DLL
00063 // #define WXDLLIMPEXP_MATHPLOT
00064 // #define WXDLLIMPEXP_DATA_MATHPLOT(type) type
00065 //#endif
00066 
00067 // Hack for MRPT: Link as part of mrpt-gui itself.
00068 #include <mrpt/gui/link_pragmas.h>
00069 #define WXDLLIMPEXP_MATHPLOT GUI_IMPEXP
00070 
00071 
00072 #if defined(__GNUG__) && !defined(__APPLE__)
00073 #pragma interface "mathplot.h"
00074 #endif
00075 
00076 #include <vector>
00077 
00078 // #include <wx/wx.h>
00079 #include <wx/defs.h>
00080 #include <wx/menu.h>
00081 #include <wx/scrolwin.h>
00082 #include <wx/event.h>
00083 #include <wx/dynarray.h>
00084 #include <wx/pen.h>
00085 #include <wx/dcmemory.h>
00086 #include <wx/string.h>
00087 #include <wx/print.h>
00088 #include <wx/image.h>
00089 
00090 
00091 #include <deque>
00092 
00093 // For memory leak debug
00094 #ifdef _WINDOWS
00095 #ifdef _DEBUG
00096 #include <crtdbg.h>
00097 #define DEBUG_NEW new(_NORMAL_BLOCK ,__FILE__, __LINE__)
00098 #else
00099 #define DEBUG_NEW new
00100 #endif // _DEBUG
00101 #endif // _WINDOWS
00102 
00103 // Separation for axes when set close to border
00104 #define X_BORDER_SEPARATION 40
00105 #define Y_BORDER_SEPARATION 60
00106 
00107 //-----------------------------------------------------------------------------
00108 // classes
00109 //-----------------------------------------------------------------------------
00110 
00111 class WXDLLIMPEXP_MATHPLOT mpLayer;
00112 class WXDLLIMPEXP_MATHPLOT mpFX;
00113 class WXDLLIMPEXP_MATHPLOT mpFY;
00114 class WXDLLIMPEXP_MATHPLOT mpFXY;
00115 class WXDLLIMPEXP_MATHPLOT mpFXYVector;
00116 class WXDLLIMPEXP_MATHPLOT mpScaleX;
00117 class WXDLLIMPEXP_MATHPLOT mpScaleY;
00118 class WXDLLIMPEXP_MATHPLOT mpWindow;
00119 class WXDLLIMPEXP_MATHPLOT mpText;
00120 class WXDLLIMPEXP_MATHPLOT mpPrintout;
00121 
00122 /** Command IDs used by mpWindow */
00123 enum
00124 {
00125     mpID_FIT = 2000,    //!< Fit view to match bounding box of all layers
00126     mpID_ZOOM_IN,       //!< Zoom into view at clickposition / window center
00127     mpID_ZOOM_OUT,      //!< Zoom out
00128     mpID_CENTER,        //!< Center view on click position
00129     mpID_LOCKASPECT,    //!< Lock x/y scaling aspect
00130     mpID_HELP_MOUSE,    //!< Shows information about the mouse commands
00131     mpID_PRINT                  //!< JL: Prints the graph
00132 };
00133 
00134 //-----------------------------------------------------------------------------
00135 // mpLayer
00136 //-----------------------------------------------------------------------------
00137 
00138 typedef enum __mp_Layer_Type {
00139     mpLAYER_UNDEF,  //!< Layer type undefined
00140     mpLAYER_AXIS,  //!< Axis type layer
00141     mpLAYER_PLOT,  //!< Plot type layer
00142     mpLAYER_INFO,   //!< Info box type layer
00143     mpLAYER_BITMAP //!< Bitmap type layer
00144 } mpLayerType;
00145 
00146 /** Plot layer, abstract base class.
00147     Any number of mpLayer implementations can be attached to mpWindow.
00148     Examples for mpLayer implementations are function graphs, or scale rulers.
00149 
00150     For convenience mpLayer defines a name, a font (wxFont), a pen (wxPen),
00151     and a continuity property (bool) as class members.
00152     The default values at constructor are the default font, a black pen, and
00153      continuity set to false (draw separate points).
00154     These may or may not be used by implementations.
00155 */
00156 class WXDLLIMPEXP_MATHPLOT mpLayer : public wxObject
00157 {
00158 public:
00159     mpLayer();
00160 
00161     virtual ~mpLayer() {};
00162 
00163     /** Check whether this layer has a bounding box.
00164         The default implementation returns \a TRUE. Override and return
00165         FALSE if your mpLayer implementation should be ignored by the calculation
00166         of the global bounding box for all layers in a mpWindow.
00167         @retval TRUE Has bounding box
00168         @retval FALSE Has not bounding box
00169     */
00170     virtual bool   HasBBox() { return TRUE; }
00171 
00172     /** Check whether the layer is an info box.
00173         The default implementation returns \a FALSE. It is overrided to \a TRUE for mpInfoLayer
00174         class and its derivative. It is necessary to define mouse actions behaviour over
00175         info boxes.
00176         @return whether the layer is an info boxes
00177         @sa mpInfoLayer::IsInfo */
00178     virtual bool IsInfo() { return false; };
00179 
00180     /** Get inclusive left border of bounding box.
00181         @return Value
00182     */
00183     virtual double GetMinX() { return -1.0; }
00184 
00185     /** Get inclusive right border of bounding box.
00186         @return Value
00187     */
00188     virtual double GetMaxX() { return  1.0; }
00189 
00190     /** Get inclusive bottom border of bounding box.
00191         @return Value
00192     */
00193     virtual double GetMinY() { return -1.0; }
00194 
00195     /** Get inclusive top border of bounding box.
00196         @return Value
00197     */
00198     virtual double GetMaxY() { return  1.0; }
00199 
00200     /** Plot given view of layer to the given device context.
00201         An implementation of this function has to transform layer coordinates to
00202         wxDC coordinates based on the view parameters retrievable from the mpWindow
00203         passed in \a w.
00204         Note that the public methods of mpWindow: x2p,y2p and p2x,p2y are already provided
00205         which transform layer coordinates to DC pixel coordinates, and <b>user code should rely
00206         on them</b> for portability and future changes to be applied transparently, instead of
00207         implementing the following formulas manually.
00208 
00209         The passed device context \a dc has its coordinate origin set to the top-left corner
00210         of the visible area (the default). The coordinate orientation is as shown in the
00211         following picture:
00212         <pre>
00213         (wxDC origin 0,0)
00214                x-------------> ascending X ----------------+
00215                |                                           |
00216                |                                           |
00217                V ascending Y                               |
00218                    |                                           |
00219                    |                                           |
00220                    |                                           |
00221                    +-------------------------------------------+  <-- right-bottom corner of the mpWindow visible area.
00222         </pre>
00223         Note that Y ascends in downward direction, whereas the usual vertical orientation
00224         for mathematical plots is vice versa. Thus Y-orientation will be swapped usually,
00225         when transforming between wxDC and mpLayer coordinates. This change of coordinates
00226         is taken into account in the methods p2x,p2y,x2p,y2p.
00227 
00228         <b> Rules for transformation between mpLayer and wxDC coordinates </b>
00229         @code
00230         dc_X = (layer_X - mpWindow::GetPosX()) * mpWindow::GetScaleX()
00231         dc_Y = (mpWindow::GetPosY() - layer_Y) * mpWindow::GetScaleY() // swapping Y-orientation
00232 
00233         layer_X = (dc_X / mpWindow::GetScaleX()) + mpWindow::GetPosX() // scale guaranteed to be not 0
00234         layer_Y = mpWindow::GetPosY() - (dc_Y / mpWindow::GetScaleY()) // swapping Y-orientation
00235         @endcode
00236 
00237         @param dc Device context to plot to.
00238         @param w  View to plot. The visible area can be retrieved from this object.
00239         @sa mpWindow::p2x,mpWindow::p2y,mpWindow::x2p,mpWindow::y2p
00240     */
00241     virtual void   Plot(wxDC & dc, mpWindow & w) = 0;
00242 
00243     /** Get layer name.
00244         @return Name
00245     */
00246     wxString       GetName() const { return m_name; }
00247 
00248     /** Get font set for this layer.
00249         @return Font
00250     */
00251     const wxFont&  GetFont() const { return m_font; }
00252 
00253     /** Get pen set for this layer.
00254         @return Pen
00255     */
00256     const wxPen&   GetPen()  const { return m_pen;  }
00257 
00258     /** Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).
00259       * @sa GetContinuity
00260       */
00261     void SetContinuity(bool continuity) {m_continuous = continuity;}
00262 
00263     /** Gets the 'continuity' property of the layer.
00264       * @sa SetContinuity
00265       */
00266     bool GetContinuity() const {return m_continuous;}
00267 
00268     /** Shows or hides the text label with the name of the layer (default is visible).
00269       */
00270     void ShowName(bool show) { m_showName = show; };
00271 
00272     /** Set layer name
00273         @param name Name, will be copied to internal class member
00274     */
00275     void SetName(wxString name) { m_name = name; }
00276 
00277     /** Set layer font
00278         @param font Font, will be copied to internal class member
00279     */
00280     void SetFont(wxFont& font)  { m_font = font; }
00281 
00282     /** Set layer pen
00283         @param pen Pen, will be copied to internal class member
00284     */
00285     void SetPen(wxPen pen)     { m_pen  = pen;  }
00286 
00287     /** Set Draw mode: inside or outside margins. Default is outside, which allows the layer to draw up to the mpWindow border.
00288         @param drawModeOutside The draw mode to be set */
00289     void SetDrawOutsideMargins(bool drawModeOutside) { m_drawOutsideMargins = drawModeOutside; };
00290 
00291     /** Get Draw mode: inside or outside margins.
00292         @return The draw mode */
00293     bool GetDrawOutsideMargins() { return m_drawOutsideMargins; };
00294 
00295     /** 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.
00296         @param side side length in pixels
00297         @return a wxBitmap filled with layer's colour */
00298     wxBitmap GetColourSquare(int side = 16);
00299 
00300     /** Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.
00301         @return An integer indicating layer type */
00302     mpLayerType GetLayerType() { return m_type; };
00303 
00304     /** Checks whether the layer is visible or not.
00305         @return \a true if visible */
00306     bool IsVisible() {return m_visible; };
00307 
00308     /** Sets layer visibility.
00309         @param show visibility bool. */
00310     void SetVisible(bool show) { m_visible = show; };
00311 
00312         /** Get brush set for this layer.
00313                 @return brush. */
00314         const wxBrush&   GetBrush() const { return m_brush; };
00315 
00316         /** Set layer brush
00317                 @param brush brush, will be copied to internal class member     */
00318         void SetBrush(wxBrush brush) { m_brush = brush; };
00319 
00320 protected:
00321     wxFont   m_font;    //!< Layer's font
00322     wxPen    m_pen;     //!< Layer's pen
00323         wxBrush  m_brush;       //!< Layer's brush
00324     wxString m_name;    //!< Layer's name
00325     bool     m_continuous; //!< Specify if the layer will be plotted as a continuous line or a set of points.
00326     bool     m_showName;  //!< States whether the name of the layer must be shown (default is true).
00327     bool     m_drawOutsideMargins; //!< select if the layer should draw only inside margins or over all DC
00328     mpLayerType m_type; //!< Define layer type, which is assigned by constructor
00329         bool    m_visible;      //!< Toggles layer visibility
00330     DECLARE_DYNAMIC_CLASS(mpLayer)
00331 };
00332 
00333 
00334 //-----------------------------------------------------------------------------
00335 // mpInfoLayer
00336 //-----------------------------------------------------------------------------
00337 
00338 /** @class mpInfoLayer
00339     @brief Base class to create small rectangular info boxes
00340     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.
00341 */
00342 class WXDLLIMPEXP_MATHPLOT mpInfoLayer : public mpLayer
00343 {
00344 public:
00345     /** Default constructor. */
00346     mpInfoLayer();
00347 
00348     /** Complete constructor.
00349         @param rect Sets the initial size rectangle of the layer.
00350         @param brush pointer to a fill brush. Default is transparent */
00351     mpInfoLayer(wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH);
00352 
00353     /** Destructor */
00354     virtual ~mpInfoLayer();
00355 
00356     /** Updates the content of the info box. Should be overidden by derived classes.
00357         Update may behave in different ways according to the type of event which called it.
00358         @param w parent mpWindow from which to obtain informations
00359         @param event The event which called the update. */
00360     virtual void UpdateInfo(mpWindow& w, wxEvent& event);
00361 
00362     /** mpInfoLayer has not bounding box. @sa mpLayer::HasBBox
00363         @return always \a FALSE */
00364     virtual bool HasBBox() { return false; };
00365 
00366     /** Plot method. Can be overidden by derived classes.
00367         @param dc the device content where to plot
00368         @param w the window to plot
00369         @sa mpLayer::Plot */
00370     virtual void   Plot(wxDC & dc, mpWindow & w);
00371 
00372     /** Specifies that this is an Info box layer.
00373         @return always \a TRUE
00374         @sa mpLayer::IsInfo */
00375     virtual bool IsInfo() { return true; };
00376 
00377     /** Checks whether a point is inside the info box rectangle.
00378         @param point The point to be checked
00379         @return \a true if the point is inside the bounding box */
00380     virtual bool Inside(wxPoint& point);
00381 
00382     /** Moves the layer rectangle of given pixel deltas.
00383         @param delta The wxPoint container for delta coordinates along x and y. Units are in pixels. */
00384     virtual void Move(wxPoint delta);
00385 
00386     /** Updates the rectangle reference point. Used by internal methods of mpWindow to correctly move mpInfoLayers. */
00387     virtual void UpdateReference();
00388 
00389     /** Returns the position of the upper left corner of the box (in pixels)
00390         @return The rectangle position */
00391     wxPoint GetPosition();
00392 
00393     /** Returns the size of the box (in pixels)
00394         @return The rectangle size */
00395     wxSize GetSize();
00396 
00397         /** Returns the current rectangle coordinates.
00398             @return The info layer rectangle */
00399         const wxRect& GetRectangle() { return m_dim; };
00400 
00401 protected:
00402     wxRect m_dim;           //!< The bounding rectangle of the box. It may be resized dynamically by the Plot method.
00403     wxPoint m_reference;    //!< Holds the reference point for movements
00404     wxBrush m_brush;        //!< The brush to be used for the background
00405     int m_winX, m_winY;     //!< Holds the mpWindow size. Used to rescale position when window is resized.
00406 
00407     DECLARE_DYNAMIC_CLASS(mpInfoLayer)
00408 };
00409 
00410 /** @class mpInfoCoords
00411     @brief Implements an overlay box which shows the mouse coordinates in plot units.
00412     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. */
00413 class WXDLLIMPEXP_MATHPLOT mpInfoCoords : public mpInfoLayer
00414 {
00415 public:
00416     /** Default constructor */
00417     mpInfoCoords();
00418     /** Complete constructor, setting initial rectangle and background brush.
00419         @param rect The initial bounding rectangle.
00420         @param brush The wxBrush to be used for box background: default is transparent */
00421     mpInfoCoords(wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH);
00422 
00423     /** Default destructor */
00424     ~mpInfoCoords();
00425 
00426     /** Updates the content of the info box. It is used to update coordinates.
00427         @param w parent mpWindow from which to obtain information
00428         @param event The event which called the update. */
00429     virtual void UpdateInfo(mpWindow& w, wxEvent& event);
00430 
00431     /** Plot method.
00432         @param dc the device content where to plot
00433         @param w the window to plot
00434         @sa mpLayer::Plot */
00435     virtual void   Plot(wxDC & dc, mpWindow & w);
00436 
00437 protected:
00438     wxString m_content; //!< string holding the coordinates to be drawn.
00439 };
00440 
00441 /** @class mpInfoLegend
00442     @brief Implements the legend to be added to the plot
00443     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. */
00444 class WXDLLIMPEXP_MATHPLOT mpInfoLegend : public mpInfoLayer
00445 {
00446 public:
00447     /** Default constructor */
00448     mpInfoLegend();
00449 
00450     /** Complete constructor, setting initial rectangle and background brush.
00451         @param rect The initial bounding rectangle.
00452         @param brush The wxBrush to be used for box background: default is transparent
00453         @sa mpInfoLayer::mpInfoLayer */
00454     mpInfoLegend(wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH);
00455 
00456     /**  Default destructor */
00457     ~mpInfoLegend();
00458 
00459     /** Updates the content of the info box. Unused in this class.
00460         @param w parent mpWindow from which to obtain information
00461         @param event The event which called the update. */
00462     virtual void UpdateInfo(mpWindow& w, wxEvent& event);
00463 
00464     /** Plot method.
00465         @param dc the device content where to plot
00466         @param w the window to plot
00467         @sa mpLayer::Plot */
00468     virtual void   Plot(wxDC & dc, mpWindow & w);
00469 
00470 protected:
00471 
00472 };
00473 
00474 
00475 //-----------------------------------------------------------------------------
00476 // mpLayer implementations - functions
00477 //-----------------------------------------------------------------------------
00478 
00479 /** @name Label alignment constants
00480 @{*/
00481 
00482 /** @internal */
00483 #define mpALIGNMASK    0x03
00484 /** Aligns label to the right. For use with mpFX. */
00485 #define mpALIGN_RIGHT  0x00
00486 /** Aligns label to the center. For use with mpFX and mpFY. */
00487 #define mpALIGN_CENTER 0x01
00488 /** Aligns label to the left. For use with mpFX. */
00489 #define mpALIGN_LEFT   0x02
00490 /** Aligns label to the top. For use with mpFY. */
00491 #define mpALIGN_TOP    mpALIGN_RIGHT
00492 /** Aligns label to the bottom. For use with mpFY. */
00493 #define mpALIGN_BOTTOM mpALIGN_LEFT
00494 /** Aligns X axis to bottom border. For mpScaleX */
00495 #define mpALIGN_BORDER_BOTTOM  0x04
00496 /** Aligns X axis to top border. For mpScaleX */
00497 #define mpALIGN_BORDER_TOP  0x05
00498 /** Set label for X axis in normal mode */
00499 #define mpX_NORMAL  0x00
00500 /** 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. */
00501 #define mpX_TIME  0x01
00502 /** Set label for X axis in hours mode: the value is always represented as hours:minutes:seconds. */
00503 #define mpX_HOURS 0x02
00504 /** Set label for X axis in date mode: the value is always represented as yyyy-mm-dd. */
00505 #define mpX_DATE 0x03
00506 /** Set label for X axis in datetime mode: the value is always represented as yyyy-mm-ddThh:mm:ss. */
00507 #define mpX_DATETIME 0x04
00508 /** Aligns Y axis to left border. For mpScaleY */
00509 #define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
00510 /** Aligns Y axis to right border. For mpScaleY */
00511 #define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
00512 /** Aligns label to north-east. For use with mpFXY. */
00513 #define mpALIGN_NE     0x00
00514 /** Aligns label to north-west. For use with mpFXY. */
00515 #define mpALIGN_NW     0x01
00516 /** Aligns label to south-west. For use with mpFXY. */
00517 #define mpALIGN_SW     0x02
00518 /** Aligns label to south-east. For use with mpFXY. */
00519 #define mpALIGN_SE     0x03
00520 
00521 /*@}*/
00522 
00523 /** @name mpLayer implementations - functions
00524 @{*/
00525 
00526 /** Abstract base class providing plot and labeling functionality for functions F:X->Y.
00527     Override mpFX::GetY to implement a function.
00528     Optionally implement a constructor and pass a name (label) and a label alignment
00529     to the constructor mpFX::mpFX. If the layer name is empty, no label will be plotted.
00530 */
00531 class WXDLLIMPEXP_MATHPLOT mpFX : public mpLayer
00532 {
00533 public:
00534     /** @param name  Label
00535         @param flags Label alignment, pass one of #mpALIGN_RIGHT, #mpALIGN_CENTER, #mpALIGN_LEFT.
00536     */
00537     mpFX(wxString name = wxEmptyString, int flags = mpALIGN_RIGHT);
00538 
00539     /** Get function value for argument.
00540         Override this function in your implementation.
00541         @param x Argument
00542         @return Function value
00543     */
00544     virtual double GetY( double x ) = 0;
00545 
00546     /** Layer plot handler.
00547         This implementation will plot the function in the visible area and
00548         put a label according to the aligment specified.
00549     */
00550     virtual void Plot(wxDC & dc, mpWindow & w);
00551 
00552 protected:
00553     int m_flags; //!< Holds label alignment
00554 
00555     DECLARE_DYNAMIC_CLASS(mpFX)
00556 };
00557 
00558 /** Abstract base class providing plot and labeling functionality for functions F:Y->X.
00559     Override mpFY::GetX to implement a function.
00560     Optionally implement a constructor and pass a name (label) and a label alignment
00561     to the constructor mpFY::mpFY. If the layer name is empty, no label will be plotted.
00562 */
00563 class WXDLLIMPEXP_MATHPLOT mpFY : public mpLayer
00564 {
00565 public:
00566     /** @param name  Label
00567         @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP.
00568     */
00569     mpFY(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
00570 
00571     /** Get function value for argument.
00572         Override this function in your implementation.
00573         @param y Argument
00574         @return Function value
00575     */
00576     virtual double GetX( double y ) = 0;
00577 
00578     /** Layer plot handler.
00579         This implementation will plot the function in the visible area and
00580         put a label according to the aligment specified.
00581     */
00582     virtual void Plot(wxDC & dc, mpWindow & w);
00583 
00584 protected:
00585     int m_flags; //!< Holds label alignment
00586 
00587     DECLARE_DYNAMIC_CLASS(mpFY)
00588 };
00589 
00590 /** Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
00591     Locus argument N is assumed to be in range 0 .. MAX_N, and implicitly derived by enumerating
00592     all locus values. Override mpFXY::Rewind and mpFXY::GetNextXY to implement a locus.
00593     Optionally implement a constructor and pass a name (label) and a label alignment
00594     to the constructor mpFXY::mpFXY. If the layer name is empty, no label will be plotted.
00595 */
00596 class WXDLLIMPEXP_MATHPLOT mpFXY : public mpLayer
00597 {
00598 public:
00599     /** @param name  Label
00600         @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
00601     */
00602     mpFXY(wxString name = wxEmptyString, int flags = mpALIGN_NE);
00603 
00604     /** Rewind value enumeration with mpFXY::GetNextXY.
00605         Override this function in your implementation.
00606     */
00607     virtual void Rewind() = 0;
00608 
00609     /** Get locus value for next N.
00610         Override this function in your implementation.
00611         @param x Returns X value
00612         @param y Returns Y value
00613     */
00614     virtual bool GetNextXY(double & x, double & y) = 0;
00615 
00616     /** Layer plot handler.
00617         This implementation will plot the locus in the visible area and
00618         put a label according to the alignment specified.
00619     */
00620     virtual void Plot(wxDC & dc, mpWindow & w);
00621 
00622 
00623 protected:
00624     int m_flags; //!< Holds label alignment
00625 
00626         // Data to calculate label positioning
00627         wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
00628         //int drawnPoints;
00629 
00630     /** Update label positioning data
00631             @param xnew New x coordinate
00632                 @param ynew New y coordinate
00633         */
00634         void UpdateViewBoundary(wxCoord xnew, wxCoord ynew);
00635 
00636     DECLARE_DYNAMIC_CLASS(mpFXY)
00637 };
00638 
00639 /** Abstract base class providing plot and labeling functionality for functions F:Y->X.
00640     Override mpProfile::GetX to implement a function.
00641     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.
00642     Optionally implement a constructor and pass a name (label) and a label alignment
00643     to the constructor mpProfile::mpProfile. If the layer name is empty, no label will be plotted.
00644 */
00645 class WXDLLIMPEXP_MATHPLOT mpProfile : public mpLayer
00646 {
00647 public:
00648     /** @param name  Label
00649         @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP.
00650     */
00651     mpProfile(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
00652 
00653     /** Get function value for argument.
00654         Override this function in your implementation.
00655         @param x Argument
00656         @return Function value
00657     */
00658     virtual double GetY( double x ) = 0;
00659 
00660     /** Layer plot handler.
00661         This implementation will plot the function in the visible area and
00662         put a label according to the aligment specified.
00663     */
00664     virtual void Plot(wxDC & dc, mpWindow & w);
00665 
00666 protected:
00667     int m_flags; //!< Holds label alignment
00668 
00669     DECLARE_DYNAMIC_CLASS(mpProfile)
00670 };
00671 
00672 /*@}*/
00673 
00674 //-----------------------------------------------------------------------------
00675 // mpLayer implementations - furniture (scales, ...)
00676 //-----------------------------------------------------------------------------
00677 
00678 /** @name mpLayer implementations - furniture (scales, ...)
00679 @{*/
00680 
00681 /** Plot layer implementing a x-scale ruler.
00682     The ruler is fixed at Y=0 in the coordinate system. A label is plotted at
00683     the bottom-right hand of the ruler. The scale numbering automatically
00684     adjusts to view and zoom factor.
00685 */
00686 class WXDLLIMPEXP_MATHPLOT mpScaleX : public mpLayer
00687 {
00688 public:
00689     /** Full constructor.
00690                 @param name Label to plot by the ruler
00691                 @param flags Set the position of the scale with respect to the window.
00692                 @param ticks Select ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid.
00693                 @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */
00694     mpScaleX(wxString name = wxT("X"), int flags = mpALIGN_CENTER, bool ticks = true, unsigned int type = mpX_NORMAL);
00695 
00696     /** Layer plot handler.
00697         This implementation will plot the ruler adjusted to the visible area. */
00698     virtual void Plot(wxDC & dc, mpWindow & w);
00699 
00700     /** Check whether this layer has a bounding box.
00701         This implementation returns \a FALSE thus making the ruler invisible
00702         to the plot layer bounding box calculation by mpWindow. */
00703     virtual bool HasBBox() { return FALSE; }
00704 
00705     /** Set X axis alignment.
00706         @param align alignment (choose between mpALIGN_BORDER_BOTTOM, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpALIGN_BORDER_TOP */
00707     void SetAlign(int align) { m_flags = align; };
00708 
00709     /** Set X axis ticks or grid
00710         @param ticks TRUE to plot axis ticks, FALSE to plot grid. */
00711     void SetTicks(bool ticks) { m_ticks = ticks; };
00712 
00713     /** Get X axis ticks or grid
00714         @return TRUE if plot is drawing axis ticks, FALSE if the grid is active. */
00715     bool GetTicks() { return m_ticks; };
00716 
00717     /** Get X axis label view mode.
00718         @return mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */
00719     unsigned int GetLabelMode() { return m_labelType; };
00720 
00721     /** Set X axis label view mode.
00722         @param mode mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds. */
00723     void SetLabelMode(unsigned int mode) { m_labelType = mode; };
00724 
00725         /** Set X axis Label format (used for mpX_NORMAL draw mode).
00726             @param format The format string */
00727         void SetLabelFormat(const wxString& format) { m_labelFormat = format; };
00728 
00729         /** Get X axis Label format (used for mpX_NORMAL draw mode).
00730         @return The format string */
00731         const wxString& SetLabelFormat() { return m_labelFormat; };
00732 
00733 protected:
00734     int m_flags; //!< Flag for axis alignment
00735     bool m_ticks; //!< Flag to toggle between ticks or grid
00736     unsigned int m_labelType; //!< Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds
00737         wxString m_labelFormat; //!< Format string used to print labels
00738 
00739     DECLARE_DYNAMIC_CLASS(mpScaleX)
00740 };
00741 
00742 /** Plot layer implementing a y-scale ruler.
00743     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
00744     the top-right hand of the ruler. The scale numbering automatically
00745     adjusts to view and zoom factor.
00746 */
00747 class WXDLLIMPEXP_MATHPLOT mpScaleY : public mpLayer
00748 {
00749 public:
00750     /** @param name Label to plot by the ruler
00751         @param flags Set position of the scale respect to the window.
00752         @param ticks Select ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid */
00753     mpScaleY(wxString name = wxT("Y"), int flags = mpALIGN_CENTER, bool ticks = true);
00754 
00755     /** Layer plot handler.
00756         This implementation will plot the ruler adjusted to the visible area.
00757     */
00758     virtual void Plot(wxDC & dc, mpWindow & w);
00759 
00760     /** Check whether this layer has a bounding box.
00761         This implementation returns \a FALSE thus making the ruler invisible
00762         to the plot layer bounding box calculation by mpWindow.
00763     */
00764     virtual bool HasBBox() { return FALSE; }
00765 
00766     /** Set Y axis alignment.
00767         @param align alignment (choose between mpALIGN_BORDER_LEFT, mpALIGN_LEFT, mpALIGN_CENTER, mpALIGN_RIGHT, mpALIGN_BORDER_RIGHT) */
00768     void SetAlign(int align) { m_flags = align; };
00769 
00770     /** Set Y axis ticks or grid
00771         @param ticks TRUE to plot axis ticks, FALSE to plot grid. */
00772     void SetTicks(bool ticks) { m_ticks = ticks; };
00773 
00774     /** Get Y axis ticks or grid
00775         @return TRUE if plot is drawing axis ticks, FALSE if the grid is active. */
00776     bool GetTicks() { return m_ticks; };
00777 
00778         /** Set Y axis Label format.
00779         @param format The format string */
00780         void SetLabelFormat(const wxString& format) { m_labelFormat = format; };
00781 
00782         /** Get Y axis Label format.
00783         @return The format string */
00784         const wxString& SetLabelFormat() { return m_labelFormat; };
00785 
00786 protected:
00787     int m_flags; //!< Flag for axis alignment
00788     bool m_ticks; //!< Flag to toggle between ticks or grid
00789         wxString m_labelFormat; //!< Format string used to print labels
00790 
00791     DECLARE_DYNAMIC_CLASS(mpScaleY)
00792 };
00793 
00794 //-----------------------------------------------------------------------------
00795 // mpWindow
00796 //-----------------------------------------------------------------------------
00797 
00798 /** @name Constants defining mouse modes for mpWindow
00799 @{*/
00800 
00801 /** Mouse panning drags the view. Mouse mode for mpWindow. */
00802 #define mpMOUSEMODE_DRAG    0
00803 /** Mouse panning creates a zoom box. Mouse mode for mpWindow. */
00804 #define mpMOUSEMODE_ZOOMBOX 1
00805 
00806 /*@}*/
00807 /** Define the type for the list of layers inside mpWindow */
00808 //WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, wxLayerList );
00809 typedef std::deque<mpLayer*> wxLayerList;
00810 
00811 /** Canvas for plotting mpLayer implementations.
00812 
00813     This class defines a zoomable and moveable 2D plot canvas. Any number
00814     of mpLayer implementations (scale rulers, function plots, ...) can be
00815     attached using mpWindow::AddLayer.
00816 
00817     The canvas window provides a context menu with actions for navigating the view.
00818     The context menu can be retrieved with mpWindow::GetPopupMenu, e.g. for extending it
00819     externally.
00820 
00821     Since wxMathPlot version 0.03, the mpWindow incorporates the following features:
00822         - DoubleBuffering (Default=disabled): Can be set with EnableDoubleBuffer
00823         - Mouse based pan/zoom (Default=enabled): Can be set with EnableMousePanZoom.
00824 
00825     The mouse commands can be visualized by the user through the popup menu, and are:
00826         - Mouse Move+CTRL: Pan (Move)
00827         - Mouse Wheel: Vertical scroll
00828         - Mouse Wheel+SHIFT: Horizontal scroll
00829         - Mouse Wheel UP+CTRL: Zoom in
00830         - Mouse Wheel DOWN+CTRL: Zoom out
00831 
00832 */
00833 class WXDLLIMPEXP_MATHPLOT mpWindow : public wxWindow
00834 {
00835 public:
00836     mpWindow() {}
00837     mpWindow( wxWindow *parent, wxWindowID id,
00838                      const wxPoint &pos = wxDefaultPosition,
00839                      const wxSize &size = wxDefaultSize,
00840                      long flags = 0);
00841     ~mpWindow();
00842 
00843     /** Get reference to context menu of the plot canvas.
00844         @return Pointer to menu. The menu can be modified.
00845     */
00846     wxMenu* GetPopupMenu() { return &m_popmenu; }
00847 
00848     /** Add a plot layer to the canvas.
00849         @param layer Pointer to layer. The mpLayer object will get under control of mpWindow,
00850                      i.e. it will be delete'd on mpWindow destruction
00851         @param refreshDisplay States whether to refresh the display (UpdateAll) after adding the layer.
00852         @retval TRUE Success
00853         @retval FALSE Failure due to out of memory.
00854     */
00855     bool AddLayer( mpLayer* layer, bool refreshDisplay = true);
00856 
00857     /** Remove a plot layer from the canvas.
00858         @param layer Pointer to layer. The mpLayer object will be destructed using delete.
00859         @param alsoDeleteObject If set to true, the mpLayer object will be also "deleted", not just removed from the internal list.
00860         @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the layer.
00861         @return true if layer is deleted correctly
00862 
00863         N.B. Only the layer reference in the mpWindow is deleted, the layer object still exists!
00864     */
00865     bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true);
00866 
00867     /** Remove all layers from the plot.
00868         @param alsoDeleteObject If set to true, the mpLayer objects will be also "deleted", not just removed from the internal list.
00869         @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the layers.
00870     */
00871     void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true);
00872 
00873 
00874     /*! Get the layer in list position indicated.
00875         N.B. You <i>must</i> know the index of the layer inside the list!
00876         @param position position of the layer in the layers list
00877         @return pointer to mpLayer
00878     */
00879     mpLayer* GetLayer(int position);
00880 
00881     /*! Get the layer by its name (case sensitive).
00882         @param name The name of the layer to retrieve
00883         @return A pointer to the mpLayer object, or NULL if not found.
00884     */
00885     mpLayer* GetLayerByName( const wxString &name);
00886 
00887     /** Get current view's X scale.
00888         See @ref mpLayer::Plot "rules for coordinate transformation"
00889         @return Scale
00890     */
00891     double GetXscl() { return m_scaleX; }
00892     double GetScaleX(void) const{ return m_scaleX; }; // Schaling's method: maybe another method esists with the same name
00893 
00894     /** Get current view's Y scale.
00895         See @ref mpLayer::Plot "rules for coordinate transformation"
00896         @return Scale
00897     */
00898     double GetYscl() const { return m_scaleY; }
00899     double GetScaleY(void) const { return m_scaleY; } // Schaling's method: maybe another method exists with the same name
00900 
00901     /** Get current view's X position.
00902         See @ref mpLayer::Plot "rules for coordinate transformation"
00903         @return X Position in layer coordinate system, that corresponds to the center point of the view.
00904     */
00905     double GetXpos() const { return m_posX; }
00906     double GetPosX(void) const { return m_posX; }
00907 
00908     /** Get current view's Y position.
00909         See @ref mpLayer::Plot "rules for coordinate transformation"
00910         @return Y Position in layer coordinate system, that corresponds to the center point of the view.
00911     */
00912     double GetYpos() const { return m_posY; }
00913     double GetPosY(void) const { return m_posY; }
00914 
00915     /** Get current view's X dimension in device context units.
00916         Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
00917         implementations should rely on the value returned by the function.
00918         See @ref mpLayer::Plot "rules for coordinate transformation"
00919         @return X dimension.
00920     */
00921     int GetScrX(void) const { return m_scrX; }
00922     int GetXScreen(void) const { return m_scrX; }
00923 
00924     /** Get current view's Y dimension in device context units.
00925         Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
00926         implementations should rely on the value returned by the function.
00927         See @ref mpLayer::Plot "rules for coordinate transformation"
00928         @return Y dimension.
00929     */
00930     int GetScrY(void) const { return m_scrY; }
00931     int GetYScreen(void) const { return m_scrY; }
00932 
00933     /** Set current view's X scale and refresh display.
00934         @param scaleX New scale, must not be 0.
00935     */
00936     void SetScaleX(double scaleX);
00937 
00938     /** Set current view's Y scale and refresh display.
00939         @param scaleY New scale, must not be 0.
00940     */
00941     void SetScaleY(double scaleY) { if (scaleY!=0) m_scaleY=scaleY; UpdateAll(); }
00942 
00943     /** Set current view's X position and refresh display.
00944         @param posX New position that corresponds to the center point of the view.
00945     */
00946     void SetPosX(double posX) { m_posX=posX; UpdateAll(); }
00947 
00948     /** Set current view's Y position and refresh display.
00949         @param posY New position that corresponds to the center point of the view.
00950     */
00951     void SetPosY(double posY) { m_posY=posY; UpdateAll(); }
00952 
00953     /** Set current view's X and Y position and refresh display.
00954         @param posX New position that corresponds to the center point of the view.
00955         @param posY New position that corresponds to the center point of the view.
00956     */
00957     void SetPos( double posX, double posY) { m_posX=posX; m_posY=posY; UpdateAll(); }
00958 
00959     /** Set current view's dimensions in device context units.
00960         Needed by plotting functions. It doesn't refresh display.
00961         @param scrX New position that corresponds to the center point of the view.
00962         @param scrY New position that corresponds to the center point of the view.
00963     */
00964     void SetScr( int scrX, int scrY) { m_scrX=scrX; m_scrY=scrY; }
00965 
00966     /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
00967       * @sa p2y,x2p,y2p */
00968 //     double p2x(wxCoord pixelCoordX, bool drawOutside = true ); // { return m_posX + pixelCoordX/m_scaleX; }
00969     inline double p2x(wxCoord pixelCoordX ) { return m_posX + pixelCoordX/m_scaleX; }
00970 
00971     /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
00972       * @sa p2x,x2p,y2p */
00973 //     double p2y(wxCoord pixelCoordY, bool drawOutside = true ); //{ return m_posY - pixelCoordY/m_scaleY; }
00974     inline double p2y(wxCoord pixelCoordY ) { return m_posY - pixelCoordY/m_scaleY; }
00975 
00976     /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
00977       * @sa p2x,p2y,y2p */
00978 //     wxCoord x2p(double x, bool drawOutside = true); // { return (wxCoord) ( (x-m_posX) * m_scaleX); }
00979     inline wxCoord x2p(double x) { return (wxCoord) ( (x-m_posX) * m_scaleX); }
00980 
00981     /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
00982       * @sa p2x,p2y,x2p */
00983 //     wxCoord y2p(double y, bool drawOutside = true); // { return (wxCoord) ( (m_posY-y) * m_scaleY); }
00984     inline wxCoord y2p(double y) { return (wxCoord) ( (m_posY-y) * m_scaleY); }
00985 
00986 
00987     /** Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
00988      */
00989     void EnableDoubleBuffer( bool enabled ) { m_enableDoubleBuffer = enabled; }
00990 
00991     /** Enable/disable the feature of pan/zoom with the mouse (default=enabled)
00992      */
00993     void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
00994 
00995     /** Enable or disable X/Y scale aspect locking for the view.
00996         @note Explicit calls to mpWindow::SetScaleX and mpWindow::SetScaleY will set
00997               an unlocked aspect, but any other action changing the view scale will
00998               lock the aspect again.
00999     */
01000     void LockAspect(bool enable = TRUE);
01001 
01002     /** Checks whether the X/Y scale aspect is locked.
01003         @retval TRUE Locked
01004         @retval FALSE Unlocked
01005     */
01006     inline bool IsAspectLocked() { return m_lockaspect; }
01007 
01008     /** Set view to fit global bounding box of all plot layers and refresh display.
01009         Scale and position will be set to show all attached mpLayers.
01010         The X/Y scale aspect lock is taken into account.
01011     */
01012     void Fit();
01013 
01014     /** Set view to fit a given bounding box and refresh display.
01015         The X/Y scale aspect lock is taken into account.
01016         If provided, the parameters printSizeX and printSizeY are taken as the DC size, and the
01017         pixel scales are computed accordingly. Also, in this case the passed borders are not saved
01018         as the "desired borders", since this use will be invoked only when printing.
01019     */
01020     void Fit(double xMin, double xMax, double yMin, double yMax,wxCoord *printSizeX=NULL,wxCoord *printSizeY=NULL);
01021 
01022     /** Zoom into current view and refresh display
01023       * @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).
01024       */
01025     void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
01026 
01027     /** Zoom out current view and refresh display
01028       * @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).
01029       */
01030     void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
01031 
01032     /** Zoom in current view along X and refresh display */
01033     void ZoomInX();
01034     /** Zoom out current view along X and refresh display */
01035     void ZoomOutX();
01036     /** Zoom in current view along Y and refresh display */
01037     void ZoomInY();
01038     /** Zoom out current view along Y and refresh display */
01039     void ZoomOutY();
01040 
01041     /** Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order) */
01042     void ZoomRect(wxPoint p0, wxPoint p1);
01043 
01044     /** Refresh display */
01045     void UpdateAll();
01046 
01047     // Added methods by Davide Rondini
01048 
01049     /** Counts the number of plot layers, excluding axes or text: this is to count only the layers which have a bounding box.
01050         \return The number of profiles plotted.
01051     */
01052     unsigned int CountLayers();
01053 
01054     /** Counts the number of plot layers, whether or not they have a bounding box.
01055         \return The number of layers in the mpWindow. */
01056     unsigned int CountAllLayers() { return m_layers.size(); };
01057 
01058     /** Draws the mpWindow on a page for printing
01059         \param print the mpPrintout where to print the graph */
01060     //void PrintGraph(mpPrintout *print);
01061 
01062     void ShowPrintDialog()
01063     {
01064         wxCommandEvent dum;
01065         OnPrintMenu(dum);
01066     }
01067 
01068 
01069         /** 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).
01070           * @sa Fit
01071           */
01072         double GetDesiredXmin() {return m_desiredXmin; }
01073 
01074         /** 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).
01075           * @sa Fit
01076           */
01077         double GetDesiredXmax() {return m_desiredXmax; }
01078 
01079         /** 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).
01080           * @sa Fit
01081           */
01082         double GetDesiredYmin() {return m_desiredYmin; }
01083 
01084         /** 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).
01085           * @sa Fit
01086           */
01087         double GetDesiredYmax() {return m_desiredYmax; }
01088 
01089         /** Returns the bounding box coordinates
01090                 @param bbox Pointer to a 6-element double array where to store bounding box coordinates. */
01091         void GetBoundingBox(double* bbox);
01092 
01093     /** Enable/disable scrollbars
01094       @param status Set to true to show scrollbars */
01095     void SetMPScrollbars(bool status);
01096 
01097     /** Get scrollbars status.
01098       @return true if scrollbars are visible */
01099     bool GetMPScrollbars() {return m_enableScrollBars; };
01100 
01101     /** Draw the window on a wxBitmap, then save it to a file.
01102       @param filename File name where to save the screenshot
01103       @param type image type to be saved: see wxImage output file types for flags
01104           @param imageSize Set a size for the output image. Default is the same as the screen size
01105           @param fit Decide whether to fit the plot into the size*/
01106     bool SaveScreenshot(const wxString& filename, int type = wxBITMAP_TYPE_BMP, wxSize imageSize = wxDefaultSize, bool fit = false);
01107 
01108     /** This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse wheel.
01109       *  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. */
01110     static double zoomIncrementalFactor;
01111 
01112     /** 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.
01113         @param top Top border
01114         @param right Right border
01115         @param bottom Bottom border
01116         @param left Left border */
01117     void SetMargins(int top, int right, int bottom, int left);
01118 
01119     /** Set the top margin. @param top Top Margin */
01120     void SetMarginTop(int top) { m_marginTop = top; };
01121     /** Set the right margin. @param right Right Margin */
01122     void SetMarginRight(int right) { m_marginRight = right; };
01123     /** Set the bottom margin. @param bottom Bottom Margin */
01124     void SetMarginBottom(int bottom) { m_marginBottom = bottom; };
01125     /** Set the left margin. @param left Left Margin */
01126     void SetMarginLeft(int left) { m_marginLeft = left; };
01127 
01128     /** Get the top margin. @param top Top Margin */
01129     int GetMarginTop() { return m_marginTop; };
01130     /** Get the right margin. @param right Right Margin */
01131     int GetMarginRight() { return m_marginRight; };
01132     /** Get the bottom margin. @param bottom Bottom Margin */
01133     int GetMarginBottom() { return m_marginBottom; };
01134     /** Get the left margin. @param left Left Margin */
01135     int GetMarginLeft() { return m_marginLeft; };
01136 
01137     /** Sets whether to show coordinate tooltip when mouse passes over the plot. \param value true for enable, false for disable */
01138     // void EnableCoordTooltip(bool value = true);
01139     /** Gets coordinate tooltip status. \return true for enable, false for disable */
01140     // bool GetCoordTooltip() { return m_coordTooltip; };
01141 
01142     /** Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.
01143         @param point The position to be checked
01144         @return If an info layer is found, returns its pointer, NULL otherwise */
01145     mpInfoLayer* IsInsideInfoLayer(wxPoint& point);
01146 
01147         /** Sets the visibility of a layer by its name.
01148                 @param name The layer name to set visibility
01149                 @param viewable the view status to be set */
01150         void SetLayerVisible(const wxString &name, bool viewable);
01151 
01152         /** Check whether a layer with given name is visible
01153                 @param name The layer name
01154                 @return layer visibility status */
01155         bool IsLayerVisible(const wxString &name );
01156 
01157         /** Sets the visibility of a layer by its position in layer list.
01158                 @param position The layer position in layer list
01159                 @param viewable the view status to be set */
01160         void SetLayerVisible(const unsigned int position, bool viewable);
01161 
01162         /** Check whether the layer at given position is visible
01163                 @param position The layer position in layer list
01164                 @return layer visibility status */
01165         bool IsLayerVisible(const unsigned int position );
01166 
01167         /** Set Color theme. Provide colours to set a new colour theme.
01168             @param bgColour Background colour
01169                 @param drawColour The colour used to draw all elements in foreground, axes excluded
01170                 @param axesColour The colour used to draw axes (but not their labels) */
01171         void SetColourTheme(const wxColour& bgColour, const wxColour& drawColour, const wxColour& axesColour);
01172 
01173         /** Get axes draw colour
01174                 @return reference to axis colour used in theme */
01175         const wxColour& GetAxesColour() { return m_axColour; };
01176 
01177 protected:
01178     void OnPaint         (wxPaintEvent     &event); //!< Paint handler, will plot all attached layers
01179     void OnSize          (wxSizeEvent      &event); //!< Size handler, will update scroll bar sizes
01180     // void OnScroll2       (wxScrollWinEvent &event); //!< Scroll handler, will move canvas
01181     void OnShowPopupMenu (wxMouseEvent     &event); //!< Mouse handler, will show context menu
01182     void OnMouseRightDown(wxMouseEvent     &event); //!< Mouse handler, for detecting when the user drags with the right button or just "clicks" for the menu
01183     void OnCenter        (wxCommandEvent   &event); //!< Context menu handler
01184     void OnFit           (wxCommandEvent   &event); //!< Context menu handler
01185     void OnZoomIn        (wxCommandEvent   &event); //!< Context menu handler
01186     void OnZoomOut       (wxCommandEvent   &event); //!< Context menu handler
01187     void OnLockAspect    (wxCommandEvent   &event); //!< Context menu handler
01188     void OnMouseHelp     (wxCommandEvent   &event); //!< Context menu handler
01189     void OnPrintMenu     (wxCommandEvent   &event); //!< Context menu handler
01190     void OnMouseWheel    (wxMouseEvent     &event); //!< Mouse handler for the wheel
01191     void OnMouseMove     (wxMouseEvent     &event); //!< Mouse handler for mouse motion (for pan)
01192     void OnMouseLeftDown (wxMouseEvent     &event); //!< Mouse left click (for rect zoom)
01193     void OnMouseLeftRelease (wxMouseEvent  &event); //!< Mouse left click (for rect zoom)
01194     void OnScrollThumbTrack (wxScrollWinEvent &event); //!< Scroll thumb on scroll bar moving
01195     void OnScrollPageUp     (wxScrollWinEvent &event); //!< Scroll page up
01196     void OnScrollPageDown   (wxScrollWinEvent &event); //!< Scroll page down
01197     void OnScrollLineUp     (wxScrollWinEvent &event); //!< Scroll line up
01198     void OnScrollLineDown   (wxScrollWinEvent &event); //!< Scroll line down
01199     void OnScrollTop        (wxScrollWinEvent &event); //!< Scroll to top
01200     void OnScrollBottom     (wxScrollWinEvent &event); //!< Scroll to bottom
01201 
01202     void DoScrollCalc    (const int position, const int orientation);
01203 
01204     void DoZoomInXCalc   (const int         staticXpixel);
01205     void DoZoomInYCalc   (const int         staticYpixel);
01206     void DoZoomOutXCalc  (const int         staticXpixel);
01207     void DoZoomOutYCalc  (const int         staticYpixel);
01208 
01209     /** Recalculate global layer bounding box, and save it in m_minX,...
01210       * \return true if there is any valid BBox information.
01211       */
01212     virtual bool UpdateBBox();
01213 
01214     //wxList m_layers;    //!< List of attached plot layers
01215     wxLayerList m_layers; //!< List of attached plot layers
01216     wxMenu m_popmenu;   //!< Canvas' context menu
01217     bool   m_lockaspect;//!< Scale aspect is locked or not
01218     // bool   m_coordTooltip; //!< Selects whether to show coordinate tooltip
01219         wxColour m_bgColour;    //!< Background Colour
01220         wxColour m_fgColour;    //!< Foreground Colour
01221         wxColour m_axColour;    //!< Axes Colour
01222 
01223     double m_minX;      //!< Global layer bounding box, left border incl.
01224     double m_maxX;      //!< Global layer bounding box, right border incl.
01225     double m_minY;      //!< Global layer bounding box, bottom border incl.
01226     double m_maxY;      //!< Global layer bounding box, top border incl.
01227     double m_scaleX;    //!< Current view's X scale
01228     double m_scaleY;    //!< Current view's Y scale
01229     double m_posX;      //!< Current view's X position
01230     double m_posY;      //!< Current view's Y position
01231     int    m_scrX;      //!< Current view's X dimension
01232     int    m_scrY;      //!< Current view's Y dimension
01233     int    m_clickedX;  //!< Last mouse click X position, for centering and zooming the view
01234     int    m_clickedY;  //!< Last mouse click Y position, for centering and zooming the view
01235 
01236     /** These are updated in Fit() only, and may be different from the real borders (layer coordinates) only if lock aspect ratio is true.
01237       */
01238     double m_desiredXmin,m_desiredXmax,m_desiredYmin,m_desiredYmax;
01239 
01240     int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
01241 
01242     int         m_last_lx,m_last_ly;   //!< For double buffering
01243     wxMemoryDC  m_buff_dc;             //!< For double buffering
01244     wxBitmap    *m_buff_bmp;            //!< For double buffering
01245     bool        m_enableDoubleBuffer;  //!< For double buffering
01246     bool        m_enableMouseNavigation;  //!< For pan/zoom with the mouse.
01247     bool        m_mouseMovedAfterRightClick;
01248     long        m_mouseRClick_X,m_mouseRClick_Y; //!< For the right button "drag" feature
01249     int         m_mouseLClick_X, m_mouseLClick_Y; //!< Starting coords for rectangular zoom selection
01250     bool        m_enableScrollBars;
01251     int         m_scrollX, m_scrollY;
01252     mpInfoLayer* m_movingInfoLayer;      //!< For moving info layers over the window area
01253 
01254     DECLARE_DYNAMIC_CLASS(mpWindow)
01255     DECLARE_EVENT_TABLE()
01256 };
01257 
01258 //-----------------------------------------------------------------------------
01259 // mpFXYVector - provided by Jose Luis Blanco
01260 //-----------------------------------------------------------------------------
01261 
01262 /** A class providing graphs functionality for a 2D plot (either continuous or a set of points), from vectors of data.
01263      This class can be used directly, the user does not need to derive any new class. Simply pass the data as two vectors
01264      with the same length containing the X and Y coordinates to the method SetData.
01265 
01266      To generate a graph with a set of points, call
01267      \code
01268      layerVar->SetContinuity(false)
01269      \endcode
01270 
01271      or
01272 
01273      \code
01274      layerVar->SetContinuity(true)
01275      \endcode
01276 
01277      to render the sequence of coordinates as a continuous line.
01278 
01279      (Added: Jose Luis Blanco, AGO-2007)
01280 */
01281 class WXDLLIMPEXP_MATHPLOT mpFXYVector : public mpFXY
01282 {
01283 public:
01284     /** @param name  Label
01285         @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
01286     */
01287     mpFXYVector(wxString name = wxEmptyString, int flags = mpALIGN_NE);
01288 
01289     /** Changes the internal data: the set of points to draw.
01290         Both vectors MUST be of the same length. This method DOES NOT refresh the mpWindow; do it manually.
01291       * @sa Clear
01292     */
01293     void SetData( const std::vector<double> &xs,const std::vector<double> &ys);
01294 
01295     /** Changes the internal data: the set of points to draw.
01296         Both vectors MUST be of the same length. This method DOES NOT refresh the mpWindow; do it manually.
01297       * @sa Clear
01298     */
01299     void SetData( const std::vector<float> &xs,const std::vector<float> &ys);
01300 
01301     /** Clears all the data, leaving the layer empty.
01302       * @sa SetData
01303       */
01304     void Clear();
01305 
01306     /** Returns the number of data points currently hold in X & Y.
01307       * @sa SetData
01308       */
01309         size_t GetDataLength() const
01310         {
01311                 return m_xs.size();
01312         }
01313 
01314         /** Append a new data point (x,y)
01315       * @sa SetData
01316       */
01317         void AppendDataPoint(float x, float y);
01318 
01319 protected:
01320     /** The internal copy of the set of data to draw.
01321       */
01322     std::vector<double>  m_xs,m_ys;
01323 
01324     /** The internal counter for the "GetNextXY" interface
01325       */
01326     size_t              m_index;
01327 
01328     /** Loaded at SetData
01329       */
01330     double              m_minX,m_maxX,m_minY,m_maxY;
01331 
01332     /** Rewind value enumeration with mpFXY::GetNextXY.
01333         Overridden in this implementation.
01334     */
01335     void Rewind();
01336 
01337     /** Get locus value for next N.
01338         Overridden in this implementation.
01339         @param x Returns X value
01340         @param y Returns Y value
01341     */
01342     bool GetNextXY(double & x, double & y);
01343 
01344 public:
01345     /** Returns the actual minimum X data (loaded in SetData).
01346       */
01347     double GetMinX() { return m_minX; }
01348 
01349     /** Returns the actual minimum Y data (loaded in SetData).
01350       */
01351     double GetMinY() { return m_minY; }
01352 
01353     /** Returns the actual maximum X data (loaded in SetData).
01354       */
01355     double GetMaxX() { return m_maxX; }
01356 
01357     /** Returns the actual maximum Y data (loaded in SetData).
01358       */
01359     double GetMaxY() { return m_maxY; }
01360 
01361 protected:
01362     int     m_flags; //!< Holds label alignment
01363 
01364     DECLARE_DYNAMIC_CLASS(mpFXYVector)
01365 };
01366 
01367 //-----------------------------------------------------------------------------
01368 // mpText - provided by Val Greene
01369 //-----------------------------------------------------------------------------
01370 
01371 /** Plot layer implementing a text string.
01372 The text is plotted using a percentage system 0-100%, so the actual
01373 coordinates for the location are not required, and the text stays
01374 on the plot reguardless of the other layers location and scaling
01375 factors.
01376 */
01377 class WXDLLIMPEXP_MATHPLOT mpText : public mpLayer
01378 {
01379 public:
01380     /** @param name text to be drawn in the plot
01381         @param offsetx holds offset for the X location in percentage (0-100)
01382         @param offsety holds offset for the Y location in percentage (0-100) */
01383     mpText(wxString name = wxT("Title"), int offsetx = 5, int offsety = 50);
01384 
01385     /** Text Layer plot handler.
01386         This implementation will plot text adjusted to the visible area. */
01387     virtual void Plot(wxDC & dc, mpWindow & w);
01388 
01389     /** mpText should not be used for scaling decisions. */
01390     virtual bool HasBBox() { return FALSE; }
01391 
01392 protected:
01393     int m_offsetx; //!< Holds offset for X in percentage
01394     int m_offsety; //!< Holds offset for Y in percentage
01395 
01396     DECLARE_DYNAMIC_CLASS(mpText)
01397 };
01398 
01399 
01400 //-----------------------------------------------------------------------------
01401 // mpPrintout - provided by Davide Rondini
01402 //-----------------------------------------------------------------------------
01403 
01404 /** Printout class used by mpWindow to draw in the objects to be printed.
01405     The object itself can then used by the default wxWidgets printing system
01406     to print mppWindow objects.
01407 */
01408 class WXDLLIMPEXP_MATHPLOT mpPrintout : public wxPrintout
01409 {
01410 public:
01411     mpPrintout(mpWindow* drawWindow, const wxChar *title = _T("wxMathPlot print output"));
01412     virtual ~mpPrintout() {};
01413 
01414     void SetDrawState(bool drawState) {drawn = drawState;};
01415     bool OnPrintPage(int page);
01416     bool HasPage(int page);
01417 
01418 private:
01419     bool drawn;
01420     mpWindow *plotWindow;
01421 };
01422 
01423 
01424 //-----------------------------------------------------------------------------
01425 // mpMovableObject  - provided by Jose Luis Blanco
01426 //-----------------------------------------------------------------------------
01427 /** This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
01428   *  The current transformation is set through SetCoordinateBase.
01429   *  To ease the implementation of descendent classes, mpMovableObject will
01430   *  be in charge of Bounding Box computation and layer rendering, assuming that
01431   *  the object updates its shape in m_shape_xs & m_shape_ys.
01432   */
01433 class WXDLLIMPEXP_MATHPLOT mpMovableObject : public mpLayer
01434 {
01435 public:
01436     /** Default constructor (sets location and rotation to (0,0,0))
01437       */
01438     mpMovableObject( ) :
01439         m_reference_x(0),
01440         m_reference_y(0),
01441         m_reference_phi(0),
01442         m_shape_xs(0),
01443         m_shape_ys(0)
01444     {
01445         m_type = mpLAYER_PLOT;
01446     }
01447 
01448     virtual ~mpMovableObject() {};
01449 
01450     /** Get the current coordinate transformation.
01451       */
01452     void GetCoordinateBase( double &x, double &y, double &phi ) const
01453     {
01454         x = m_reference_x;
01455         y = m_reference_y;
01456         phi = m_reference_phi;
01457     }
01458 
01459     /** Set the coordinate transformation (phi in radians, 0 means no rotation).
01460       */
01461     void SetCoordinateBase( double x, double y, double phi = 0 )
01462     {
01463         m_reference_x = x;
01464         m_reference_y = y;
01465         m_reference_phi = phi;
01466         m_flags  = mpALIGN_NE;
01467         ShapeUpdated();
01468     }
01469 
01470     virtual bool HasBBox() { return m_trans_shape_xs.size()!=0; }
01471 
01472     /** Get inclusive left border of bounding box.
01473     */
01474     virtual double GetMinX() { return m_bbox_min_x; }
01475 
01476     /** Get inclusive right border of bounding box.
01477     */
01478     virtual double GetMaxX() { return  m_bbox_max_x; }
01479 
01480     /** Get inclusive bottom border of bounding box.
01481     */
01482     virtual double GetMinY() { return m_bbox_min_y; }
01483 
01484     /** Get inclusive top border of bounding box.
01485     */
01486     virtual double GetMaxY() { return m_bbox_max_y; }
01487 
01488     virtual void   Plot(wxDC & dc, mpWindow & w);
01489 
01490     /** Set label axis alignment.
01491       *  @param align alignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE
01492       */
01493     void SetAlign(int align) { m_flags = align; };
01494 
01495 protected:
01496     int m_flags; //!< Holds label alignment
01497 
01498     /** The coordinates of the object (orientation "phi" is in radians).
01499       */
01500     double m_reference_x,m_reference_y,m_reference_phi;
01501 
01502     /** A method for 2D translation and rotation, using the current transformation stored in m_reference_x,m_reference_y,m_reference_phi.
01503       */
01504     void TranslatePoint( double x,double y, double &out_x, double &out_y );
01505 
01506     /** This contains the object points, in local coordinates (to be transformed by the current transformation).
01507       */
01508     std::vector<double>  m_shape_xs,m_shape_ys;
01509 
01510     /** The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh).
01511       *
01512       */
01513     std::vector<double>  m_trans_shape_xs,m_trans_shape_ys;
01514 
01515     /** The precomputed bounding box:
01516       * @sa ShapeUpdated
01517       */
01518     double  m_bbox_min_x,m_bbox_max_x,m_bbox_min_y,m_bbox_max_y;
01519 
01520     /** Must be called by the descendent class after updating the shape (m_shape_xs/ys), or when the transformation changes.
01521       *  This method updates the buffers m_trans_shape_xs/ys, and the precomputed bounding box.
01522       */
01523     void ShapeUpdated();
01524 
01525 };
01526 
01527 //-----------------------------------------------------------------------------
01528 // mpCovarianceEllipse  - provided by Jose Luis Blanco
01529 //-----------------------------------------------------------------------------
01530 /** A 2D ellipse, described by a 2x2 covariance matrix.
01531   *  The relation between the multivariate Gaussian confidence interval and
01532   *   the "quantiles" in this class is:
01533   *     - 1 : 68.27% confidence interval
01534   *     - 2 : 95.45%
01535   *     - 3 : 99.73%
01536   *     - 4 : 99.994%
01537   * For example, see http://en.wikipedia.org/wiki/Normal_distribution#Standard_deviation_and_confidence_intervals
01538   *
01539   * The ellipse will be always centered at the origin. Use mpMovableObject::SetCoordinateBase to move it.
01540   */
01541 class WXDLLIMPEXP_MATHPLOT mpCovarianceEllipse : public mpMovableObject
01542 {
01543 public:
01544     /** Default constructor.
01545       * Initializes to a unity diagonal covariance matrix, a 95% confidence interval (2 sigmas), 32 segments, and a continuous plot (m_continuous=true).
01546       */
01547     mpCovarianceEllipse(
01548         double cov_00 = 1,
01549         double cov_11 = 1,
01550         double cov_01 = 0,
01551         double quantiles = 2,
01552         int    segments = 32,
01553         const wxString & layerName = wxT("") ) :
01554             m_cov_00(cov_00),
01555             m_cov_11(cov_11),
01556             m_cov_01(cov_01),
01557             m_quantiles(quantiles),
01558             m_segments(segments)
01559     {
01560         m_continuous = true;
01561         m_name = layerName;
01562         RecalculateShape();
01563         m_type = mpLAYER_PLOT;
01564     }
01565 
01566     virtual ~mpCovarianceEllipse() {}
01567 
01568     double GetQuantiles() const { return m_quantiles; }
01569 
01570     /** Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above).
01571       */
01572     void SetQuantiles(double q)
01573     {
01574         m_quantiles=q;
01575         RecalculateShape();
01576     }
01577 
01578     void SetSegments( int segments ) { m_segments = segments; }
01579     int GetSegments( ) const { return m_segments; }
01580 
01581     /** Returns the elements of the current covariance matrix:
01582       */
01583     void GetCovarianceMatrix( double &cov_00,double &cov_01,double &cov_11 ) const
01584     {
01585         cov_00 = m_cov_00;
01586         cov_01 = m_cov_01;
01587         cov_11 = m_cov_11;
01588     }
01589 
01590     /** Changes the covariance matrix:
01591       */
01592     void SetCovarianceMatrix( double cov_00,double cov_01,double cov_11 )
01593     {
01594         m_cov_00 = cov_00;
01595         m_cov_01 = cov_01;
01596         m_cov_11 = cov_11;
01597         RecalculateShape();
01598     }
01599 
01600 protected:
01601     /** The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
01602       */
01603     double m_cov_00,m_cov_11,m_cov_01;
01604     double m_quantiles;
01605 
01606     /** The number of line segments that build up the ellipse.
01607       */
01608     int m_segments;
01609 
01610     /** Called to update the m_shape_xs, m_shape_ys vectors, whenever a parameter changes.
01611       */
01612     void RecalculateShape();
01613 };
01614 
01615 //-----------------------------------------------------------------------------
01616 // mpPolygon - provided by Jose Luis Blanco
01617 //-----------------------------------------------------------------------------
01618 /** An arbitrary polygon, descendant of mpMovableObject.
01619   *  Use "setPoints" to set the list of N points. This class also can draw non-closed polygons by
01620   *   passing the appropriate parameters to "setPoints". To draw a point-cloud, call "SetContinuity(false)".
01621   */
01622 class WXDLLIMPEXP_MATHPLOT mpPolygon : public mpMovableObject
01623 {
01624 public:
01625     /** Default constructor.
01626       */
01627     mpPolygon( const wxString & layerName = wxT("") )
01628     {
01629         m_continuous = true;
01630         m_name = layerName;
01631     }
01632 
01633     virtual ~mpPolygon() {}
01634 
01635     /** Set the points in the polygon.
01636       * @param points_xs  The X coordinates of the points.
01637       * @param points_ys  The Y coordinates of the points.
01638       * @param closedShape If set to true, an additional segment will be added from the last to the first point.
01639       */
01640     void setPoints(
01641         const std::vector<double>&  points_xs,
01642         const std::vector<double>&  points_ys,
01643         bool                   closedShape=true );
01644 
01645     /** Set the points in the polygon.
01646       * @param points_xs  The X coordinates of the points.
01647       * @param points_ys  The Y coordinates of the points.
01648       * @param closedShape If set to true, an additional segment will be added from the last to the first point.
01649       */
01650     void setPoints(
01651         const std::vector<float>&  points_xs,
01652         const std::vector<float>&  points_ys,
01653         bool                   closedShape=true );
01654 
01655 
01656 
01657 };
01658 
01659 //-----------------------------------------------------------------------------
01660 // mpMovableObject  - provided by Jose Luis Blanco
01661 //-----------------------------------------------------------------------------
01662 /** This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
01663   *  The current transformation is set through SetCoordinateBase.
01664   *  To ease the implementation of descendent classes, mpMovableObject will
01665   *  be in charge of Bounding Box computation and layer render, assuming that
01666   *  the object updates its shape in m_shape_xs & m_shape_ys.
01667   */
01668 class WXDLLIMPEXP_MATHPLOT mpBitmapLayer : public mpLayer
01669 {
01670 public:
01671     /** Default constructor.
01672       */
01673     mpBitmapLayer( )
01674     {
01675         m_min_x = m_max_x =
01676         m_min_y = m_max_y = 0;
01677         m_validImg = false;
01678         m_type = mpLAYER_BITMAP;
01679     }
01680 
01681     virtual ~mpBitmapLayer() {};
01682 
01683     /** Returns a copy of the current bitmap assigned to the layer.
01684       */
01685     void GetBitmapCopy( wxImage &outBmp ) const;
01686 
01687     /** Change the bitmap associated with the layer (to update the screen, refresh the mpWindow).
01688       *  @param inBmp The bitmap to associate. A copy is made, thus it can be released after calling this.
01689       *  @param x The left corner X coordinate (in plot units).
01690       *  @param y The top corner Y coordinate (in plot units).
01691       *  @param lx The width in plot units.
01692       *  @param ly The height in plot units.
01693       */
01694     void SetBitmap( const wxImage &inBmp, double x, double y, double lx, double ly );
01695 
01696     virtual bool HasBBox() { return true; }
01697 
01698     /** Get inclusive left border of bounding box.
01699     */
01700     virtual double GetMinX() { return m_min_x; }
01701 
01702     /** Get inclusive right border of bounding box.
01703     */
01704     virtual double GetMaxX() { return  m_max_x; }
01705 
01706     /** Get inclusive bottom border of bounding box.
01707     */
01708     virtual double GetMinY() { return m_min_y; }
01709 
01710     /** Get inclusive top border of bounding box.
01711     */
01712     virtual double GetMaxY() { return m_max_y; }
01713 
01714     virtual void   Plot(wxDC & dc, mpWindow & w);
01715 
01716     /** Set label axis alignment.
01717       *  @param align alignment (choose between mpALIGN_NE, mpALIGN_NW, mpALIGN_SW, mpALIGN_SE
01718       */
01719     void SetAlign(int align) { m_flags = align; };
01720 
01721 protected:
01722     int m_flags; //!< Holds label alignment
01723 
01724     /** The internal copy of the Bitmap:
01725       */
01726     wxImage      m_bitmap;
01727     wxBitmap     m_scaledBitmap;
01728     wxCoord      m_scaledBitmap_offset_x,m_scaledBitmap_offset_y;
01729 
01730 
01731     bool            m_validImg;
01732 
01733 
01734     /** The shape of the bitmap:
01735       */
01736     double  m_min_x,m_max_x,m_min_y,m_max_y;
01737 
01738 
01739 };
01740 
01741 
01742 
01743 /*@}*/
01744 
01745 #if defined(_MSC_VER)
01746         #pragma warning(pop)
01747 #endif
01748 
01749 
01750 #endif // _MP_MATHPLOT_H_



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011