mathplot.h

Go to the documentation of this file.
00001 
00002 // Name:        mathplot.h
00003 // Purpose:     Framework for mathematical graph plotting in wxWindows
00004 // Author:      David Schalig
00005 // Modified by:
00006 // Created:     21/07/2003
00007 // Copyright:   (c) David Schalig
00008 // Licence:     wxWindows licence
00010 
00011 #ifndef _MP_MATHPLOT_H_
00012 #define _MP_MATHPLOT_H_
00013 #define ZOOM_FACTOR 1.5
00014 
00015 /* @file mathplot.h */
00016 /* @mainpage wxMathPlot
00017 wxMathPlot is a framework for mathematical graph plotting in wxWindows.
00018 
00019 The framework is designed for convenience and ease of use.
00020 
00021 @section screenshots Screenshots
00022 <a href="screenshots.html">Go to the screenshots page.</a>
00023 
00024 @section overview Overview
00025 The heart of wxMathPlot is mpWindow, which is a 2D canvas for plot layers.
00026 mpWindow can be embedded as subwindow in a wxPane, a wxFrame, or any other wxWindow.
00027 mpWindow provides a zoomable and moveable view of the layers. The current view can
00028 be controlled with the mouse, the scrollbars, and a context menu.
00029 
00030 Plot layers are implementations of the abstract base class mpLayer. Those can
00031 be function plots, scale rulers, or any other vector data visualisation. wxMathPlot provides
00032 two mpLayer implementations for plotting horizontal and vertical rulers: mpScaleX and mpScaleY.
00033 For convenient function plotting three more abstract base classes derived from mpLayer
00034 are provided: mpFX, mpFY and mpFXY. These base classes already come with plot code, own
00035 functions can be implemented by overiding just one member for retrieving a function value.
00036 
00037 @section coding Coding conventions
00038 wxMathPlot sticks to wxWindow's coding conventions. All entities defined by wxMathPlot
00039 have the prefix <i>mp</i>.
00040 
00041 @section author Author and license
00042 wxMathPlot is published under the terms of the wxWindow license.
00043 The author David Schalig can be contacted via the wxMathPlot's homepage at
00044 http://sourceforge.net/projects/wxmathplot
00045 */
00046 
00047 /*
00048 #if defined(__GNUG__) && !defined(__APPLE__)
00049 #pragma interface "mathplot.h"
00050 #endif
00051 */
00052 
00053 #include "marTypes.h"
00054 #include "wx/defs.h"
00055 #include <wx/wx.h>
00056 
00057 /*
00058 #include "wx/menu.h"
00059 #include "wx/scrolwin.h"
00060 #include "wx/event.h"
00061 #include "wx/dynarray.h"
00062 */
00063 
00064 //-----------------------------------------------------------------------------
00065 // classes
00066 //-----------------------------------------------------------------------------
00067 
00068 class  mpLayer;
00069 class  mpFX;
00070 class  mpFY;
00071 class  mpFXY;
00072 class  mpScaleX;
00073 class  mpScaleY;
00074 class  mpWindow;
00075 
00077 enum
00078 {
00079         mpID_FIT = 2000,    
00080         mpID_ZOOM_IN,       
00081         mpID_ZOOM_OUT,      
00082         mpID_CENTER,        
00083         mpID_LOCKASPECT,    
00084         mpID_LINE_GUIDES,       
00085 };
00086 
00087 //-----------------------------------------------------------------------------
00088 // mpLayer
00089 //-----------------------------------------------------------------------------
00090 
00098 class creaMaracasVisu_EXPORT mpLayer : public wxObject
00099 {
00100 public:
00101         mpLayer();
00102 
00110         virtual bool   HasBBox() { return TRUE; }
00111 
00115         virtual double GetMinX() { return -1.0; }
00116 
00120         virtual double GetMaxX() { return  1.0; }
00121 
00125         virtual double GetMinY() { return -1.0; }
00126 
00130         virtual double GetMaxY() { return  1.0; }
00131 
00165         virtual void   Plot(wxDC & dc, mpWindow & w) = 0;
00166 
00170         wxString       GetName() const { return m_name; }
00171 
00175         const wxFont&  GetFont() const { return m_font; }
00176 
00180         const wxPen&   GetPen()  const { return m_pen;  }
00181 
00185         void SetName(wxString name) { m_name = name; }
00186 
00190         void SetFont(wxFont& font)  { m_font = font; }
00191 
00195         void SetPen(wxPen& pen)     { m_pen  = pen;  }
00196 
00201         int GetYTranslated(double sizey, double y){
00202                 return -y+sizey;
00203         }
00204 
00205 protected:
00206         wxFont   m_font;    
00207         wxPen    m_pen;     
00208         wxString m_name;    
00209 
00210         DECLARE_CLASS(mpLayer)
00211 };
00212 
00213 //-----------------------------------------------------------------------------
00214 // mpLayer implementations - functions
00215 //-----------------------------------------------------------------------------
00216 
00221 #define mpALIGNMASK    0x03
00222 
00223 #define mpALIGN_RIGHT  0x00
00224 
00225 #define mpALIGN_CENTER 0x01
00226 
00227 #define mpALIGN_LEFT   0x02
00228 
00229 #define mpALIGN_TOP    mpALIGN_RIGHT
00230 
00231 #define mpALIGN_BOTTOM mpALIGN_LEFT
00232 
00233 #define mpALIGN_NE     0x00
00234 
00235 #define mpALIGN_NW     0x01
00236 
00237 #define mpALIGN_SW     0x02
00238 
00239 #define mpALIGN_SE     0x03
00240 
00251 class  mpFX : public mpLayer
00252 {
00253 public:
00257         mpFX(wxString name = wxEmptyString, int flags = mpALIGN_RIGHT);
00258 
00264         virtual double GetY( double x ) = 0;
00265 
00270         virtual void Plot(wxDC & dc, mpWindow & w);
00271 
00272 protected:
00273         int m_flags; 
00274 
00275         DECLARE_CLASS(mpFX)
00276 };
00277 
00283 class  mpFY : public mpLayer
00284 {
00285 public:
00289         mpFY(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
00290 
00296         virtual double GetX( double y ) = 0;
00297 
00302         virtual void Plot(wxDC & dc, mpWindow & w);
00303 
00304 protected:
00305         int m_flags; 
00306 
00307         DECLARE_CLASS(mpFY)
00308 };
00309 
00316 class  mpFXY : public mpLayer
00317 {
00318 public:
00322         mpFXY(wxString name = wxEmptyString, int flags = mpALIGN_NE);
00323 
00327         virtual void Rewind() = 0;
00328 
00334         virtual bool GetNextXY(double & x, double & y) = 0;
00335 
00340         virtual void Plot(wxDC & dc, mpWindow & w);
00341 
00342 protected:
00343         int m_flags; 
00344 
00345         DECLARE_CLASS(mpFXY)
00346 };
00347 
00350 //-----------------------------------------------------------------------------
00351 // mpLayer implementations - furniture (scales, ...)
00352 //-----------------------------------------------------------------------------
00353 
00362 class  mpScaleX : public mpLayer
00363 {
00364 public:
00366         mpScaleX(wxString name = wxT("X"));
00367 
00371         virtual void Plot(wxDC & dc, mpWindow & w);
00372 
00377         virtual bool HasBBox() { return FALSE; }
00378 
00379         DECLARE_CLASS(mpScaleX)
00380 };
00381 
00387 class  mpScaleY : public mpLayer
00388 {
00389 public:
00391         mpScaleY(wxString name = wxT("Y"));
00392 
00396         virtual void Plot(wxDC & dc, mpWindow & w, int orgy);
00397 
00402         virtual bool HasBBox() { return FALSE; }
00403 
00404 protected:
00405 
00406         DECLARE_CLASS(mpScaleY)
00407 };
00408 
00409 //-----------------------------------------------------------------------------
00410 // mpWindow
00411 //-----------------------------------------------------------------------------
00412 
00417 #define mpMOUSEMODE_DRAG    0
00418 
00419 #define mpMOUSEMODE_ZOOMBOX 1
00420 
00433 class creaMaracasVisu_EXPORT mpWindow : public wxScrolledWindow
00434 {
00435 public:
00436         mpWindow() {}
00437         mpWindow( wxWindow *parent, wxWindowID id,
00438                 const wxPoint &pos = wxDefaultPosition, 
00439                 const wxSize &size = wxDefaultSize,
00440                 int flags = 0);
00441         ~mpWindow();
00442 
00446         wxMenu* GetPopupMenu() { return &m_popmenu; }
00447 
00448         //-----------------------
00449         // new methods for plotter
00450         //-----------------------
00451         /*
00452          Set Type
00453         */
00454         void setType(int t)
00455         {
00456                 type=t;
00457         }
00458         /*
00459          Get Type
00460         */
00461         int getType()
00462         {
00463                 return type;
00464         }
00465                 
00466         
00471         void setMaxScrX(int maxX)
00472         {
00473                 maxScrX=maxX;
00474         }
00479         void setMaxScrY(int maxY)
00480         {
00481                 maxScrY=maxY;
00482         }
00483         
00484         
00488         double getMaxScrX()
00489         {
00490                 return maxScrX;
00491         }
00495         double getMaxScrY()
00496         {
00497                 return maxScrY;
00498         }
00499         /*
00500          returns the zoomFactor
00501         */
00502         float getZoomFactor()
00503         {
00504                 return zoomFactor;
00505         }
00510         void setMinScrX(int minX)
00511         {
00512                 minScrX=minX;
00513         }
00518         void setMinScrY(int minY)
00519         {
00520                 minScrY=minY;
00521         }
00522         
00523         
00527         double getMinScrX()
00528         {
00529                 return minScrX;
00530         }
00534         double getMinScrY()
00535         {
00536                 return minScrY;
00537         }
00538 
00543         int getClickedX()
00544         {
00545                 return m_clickedX;
00546         }
00547 
00552         int getClickedY()
00553         {
00554                 return m_clickedY;
00555         }
00556         
00561         int getOffsetPixelsX()
00562         {
00563                 return offsetPixelX;
00564         }       
00565         
00570         int getOffsetPixelsY()
00571         {
00572                 return offsetPixelY;
00573         }
00577         void setOffsetPixelX(int offX)
00578         {
00579                 offsetPixelX=offX;
00580         }
00584         void setOffsetPixelY(int offY)
00585         {
00586                 offsetPixelY=offY;
00587         }       
00588         
00592         int getOffsetX()
00593         {
00594                 return offsetX;
00595         }       
00596         
00600         int getOffsetY()
00601         {
00602                 return offsetY;
00603         }
00607         void setOffsetX(int offX)
00608         {
00609                 offsetX=offX;
00610         }
00614         void setOffsetY(int offY)
00615         {
00616                 offsetY=offY;
00617         }       
00618         
00619         /*
00620         * Sets real value of the y-coord for the vertical guide line
00621         * @param newX_realGuide The new value to assing for the vertical guide
00622         */
00623         void setRealGuideX(int newX_realGuide)
00624         {               
00625                 real_guideLine_X = newX_realGuide;      
00626                 if(real_guideLine_X!=-1)
00627                         UpdateAll();
00628         }
00629 
00630         /*
00631         * Gets the real value of the y-coord for the vertical guide line
00632         * @retval real_guideLine_X The assigned value for the vertical guide
00633         */
00634         int getRealGuideX()
00635         {
00636                 return real_guideLine_X;
00637         }       
00638 
00639         /*
00640         * Sets real value of the y-coord for the vertical guide line
00641         * @param newY_realGuide The new value to assing for the vertical guide
00642         */
00643         void setRealGuideY(int newY_realGuide)
00644         {               
00645                 real_guideLine_Y = newY_realGuide;      
00646                 if(real_guideLine_Y!=-1)
00647                         UpdateAll();
00648         }
00649 
00650         /*
00651         * Gets the real value of the y-coord for the vertical guide line
00652         * @retval real_guideLine_Y The assigned value for the vertical guide
00653         */
00654         int getRealGuideY()
00655         {
00656                 return real_guideLine_Y;
00657         }               
00658 
00659         /*
00660         * Sets the condition for drawing or not the guide lines
00661         * @param ifDrawing The new condition to assing 
00662         */
00663         /*void setLineGuidesCondition(bool ifDrawing)
00664         {               
00665                 drawGuides = ifDrawing;         
00666         }
00667         */
00668         
00669         /*
00670         * Gets the condition for drawing or not the guide lines
00671         * @retval drawGuides The assigned condition
00672         */
00673         bool drawGuideLines();
00674 
00675         /*
00676         * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
00677         * event The corresponding event to handle
00678         */
00679         
00680         //void OnGuideLines (wxCommandEvent   &event); 
00681 
00682         //----------------------------------------------------------------------------------
00683         // Previous methods
00684         //----------------------------------------------------------------------------------
00685         
00686         
00693         bool AddLayer( mpLayer* layer);
00694 
00698         void DelLayer( mpLayer* layer);
00699 
00704         double GetScaleX(void) const { return m_scaleX; }
00705 
00710         double GetScaleY(void) const { return m_scaleY; }
00711 
00716         double GetPosX(void) const { return m_posX; }
00717 
00722         double GetPosY(void) const { return m_posY; }
00723 
00730         int GetScrX(void) const { return m_scrX; }
00731 
00738         int GetScrY(void) const { return m_scrY; }
00739         //void SetScrY(int x) const { return m_scrY; }
00740 
00744         void SetScaleX(double scaleX) { if (scaleX!=0) m_scaleX=scaleX; /*UpdateAll();*/ }
00745 
00749         void SetScaleY(double scaleY) { if (scaleY!=0) m_scaleY=scaleY; /*UpdateAll();*/ }
00750 
00754         void SetPosX(double posX) { m_posX=posX; UpdateAll(); }
00755 
00759         void SetPosY(double posY) { m_posY=posY; UpdateAll(); }
00760 
00765         void SetPos( double posX, double posY) { m_posX=posX; m_posY=posY; UpdateAll(); }
00766 
00772         void LockAspect(bool enable = TRUE);
00773 
00778         inline bool IsAspectLocked() { return m_lockaspect; }
00779 
00784         void Fit();
00785 
00787         void ZoomIn();
00788 
00790         void ZoomOut();
00791 
00793         void UpdateAll();
00794 
00798         int GetYTranslated(wxSize size, double y){
00799                 return size.GetHeight()-y;
00800         }
00801 
00802 protected:
00803 
00804         void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
00805         void OnPaint         (wxPaintEvent     &event); 
00806         void OnSize          (wxSizeEvent      &event); 
00807         void OnScroll2       (wxScrollWinEvent &event); 
00808         void OnShowPopupMenu (wxMouseEvent     &event); 
00809         void OnCenter        (wxCommandEvent   &event); 
00810         void OnFit           (wxCommandEvent   &event); 
00811         void OnZoomIn        (wxCommandEvent   &event); 
00812         void OnZoomOut       (wxCommandEvent   &event); 
00813         void OnLockAspect    (wxCommandEvent   &event); 
00814         
00815 
00816         bool UpdateBBox(); 
00817 
00818         wxList m_layers;    
00819         wxMenu m_popmenu;   
00820         bool   m_lockaspect;
00821 
00822         double m_minX;      
00823         double m_maxX;      
00824         double m_minY;      
00825         double m_maxY;      
00826         double m_scaleX;    
00827         double m_scaleY;    
00828         double m_posX;      
00829         double m_posY;      
00830         int    m_scrX;      
00831         int    m_scrY;      
00832         int    m_clickedX;  
00833         int    m_clickedY;  
00834         
00835         //----------------------------------------------
00836         //NEW ATTRIBUTES FOR COMPATIBILITY WITH PPlotter
00837         //----------------------------------------------
00841         int    maxScrX;
00842         
00846         int    maxScrY;
00850         int  minScrX;
00851         
00855         int  minScrY;
00856         /*
00857          the zoom factor
00858          of the zoom
00859         */
00860         float      zoomFactor;
00861 
00862         
00867         int offsetPixelX;
00868         int offsetPixelY;
00869         /*
00870          Offsets in real value according to the actual function
00871         */
00872         int offsetX;
00873         int offsetY;
00874 
00875         /*
00876         * The real value of the y-coord for the horizontal guide line
00877         */
00878         int real_guideLine_X;
00879         /*
00880         * The real value of the y-coord for the vertical guide line
00881         */
00882         int real_guideLine_Y;
00883 
00884         /*
00885         * Represents the condition for drawing or not the line guides, default color is red and assigned to draw them
00886         */
00887         bool drawGuides;
00888         /*
00889          Use to know which type of plotter is
00890          1= default Plotter
00891          2= histogram plotter
00892         */
00893          int type;
00894 
00895  private:
00896         //bitmap of functions
00897         wxBitmap        *_bitmap_functions;
00898 
00899 
00900         DECLARE_CLASS(mpWindow)
00901         DECLARE_EVENT_TABLE()
00902 };
00903 
00904 #endif // _MP_MATHPLOT_H_

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1