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 
00197 protected:
00198         wxFont   m_font;    
00199         wxPen    m_pen;     
00200         wxString m_name;    
00201 
00202         DECLARE_CLASS(mpLayer)
00203 };
00204 
00205 //-----------------------------------------------------------------------------
00206 // mpLayer implementations - functions
00207 //-----------------------------------------------------------------------------
00208 
00213 #define mpALIGNMASK    0x03
00214 
00215 #define mpALIGN_RIGHT  0x00
00216 
00217 #define mpALIGN_CENTER 0x01
00218 
00219 #define mpALIGN_LEFT   0x02
00220 
00221 #define mpALIGN_TOP    mpALIGN_RIGHT
00222 
00223 #define mpALIGN_BOTTOM mpALIGN_LEFT
00224 
00225 #define mpALIGN_NE     0x00
00226 
00227 #define mpALIGN_NW     0x01
00228 
00229 #define mpALIGN_SW     0x02
00230 
00231 #define mpALIGN_SE     0x03
00232 
00243 class  mpFX : public mpLayer
00244 {
00245 public:
00249         mpFX(wxString name = wxEmptyString, int flags = mpALIGN_RIGHT);
00250 
00256         virtual double GetY( double x ) = 0;
00257 
00262         virtual void Plot(wxDC & dc, mpWindow & w);
00263 
00264 protected:
00265         int m_flags; 
00266 
00267         DECLARE_CLASS(mpFX)
00268 };
00269 
00275 class  mpFY : public mpLayer
00276 {
00277 public:
00281         mpFY(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
00282 
00288         virtual double GetX( double y ) = 0;
00289 
00294         virtual void Plot(wxDC & dc, mpWindow & w);
00295 
00296 protected:
00297         int m_flags; 
00298 
00299         DECLARE_CLASS(mpFY)
00300 };
00301 
00308 class  mpFXY : public mpLayer
00309 {
00310 public:
00314         mpFXY(wxString name = wxEmptyString, int flags = mpALIGN_NE);
00315 
00319         virtual void Rewind() = 0;
00320 
00326         virtual bool GetNextXY(double & x, double & y) = 0;
00327 
00332         virtual void Plot(wxDC & dc, mpWindow & w);
00333 
00334 protected:
00335         int m_flags; 
00336 
00337         DECLARE_CLASS(mpFXY)
00338 };
00339 
00342 //-----------------------------------------------------------------------------
00343 // mpLayer implementations - furniture (scales, ...)
00344 //-----------------------------------------------------------------------------
00345 
00354 class  mpScaleX : public mpLayer
00355 {
00356 public:
00358         mpScaleX(wxString name = wxT("X"));
00359 
00363         virtual void Plot(wxDC & dc, mpWindow & w);
00364 
00369         virtual bool HasBBox() { return FALSE; }
00370 
00371         DECLARE_CLASS(mpScaleX)
00372 };
00373 
00379 class  mpScaleY : public mpLayer
00380 {
00381 public:
00383         mpScaleY(wxString name = wxT("Y"));
00384 
00388         virtual void Plot(wxDC & dc, mpWindow & w);
00389 
00394         virtual bool HasBBox() { return FALSE; }
00395 
00396 protected:
00397 
00398         DECLARE_CLASS(mpScaleY)
00399 };
00400 
00401 //-----------------------------------------------------------------------------
00402 // mpWindow
00403 //-----------------------------------------------------------------------------
00404 
00409 #define mpMOUSEMODE_DRAG    0
00410 
00411 #define mpMOUSEMODE_ZOOMBOX 1
00412 
00425 class creaMaracasVisu_EXPORT mpWindow : public wxScrolledWindow
00426 {
00427 public:
00428         mpWindow() {}
00429         mpWindow( wxWindow *parent, wxWindowID id,
00430                 const wxPoint &pos = wxDefaultPosition, 
00431                 const wxSize &size = wxDefaultSize,
00432                 int flags = 0);
00433         ~mpWindow();
00434 
00438         wxMenu* GetPopupMenu() { return &m_popmenu; }
00439 
00440         //-----------------------
00441         // new methods for plotter
00442         //-----------------------
00443         /*
00444          Set Type
00445         */
00446         void setType(int t)
00447         {
00448                 type=t;
00449         }
00450         /*
00451          Get Type
00452         */
00453         int getType()
00454         {
00455                 return type;
00456         }
00457                 
00458         
00463         void setMaxScrX(int maxX)
00464         {
00465                 maxScrX=maxX;
00466         }
00471         void setMaxScrY(int maxY)
00472         {
00473                 maxScrY=maxY;
00474         }
00475         
00476         
00480         double getMaxScrX()
00481         {
00482                 return maxScrX;
00483         }
00487         double getMaxScrY()
00488         {
00489                 return maxScrY;
00490         }
00491         /*
00492          returns the zoomFactor
00493         */
00494         float getZoomFactor()
00495         {
00496                 return zoomFactor;
00497         }
00502         void setMinScrX(int minX)
00503         {
00504                 minScrX=minX;
00505         }
00510         void setMinScrY(int minY)
00511         {
00512                 minScrY=minY;
00513         }
00514         
00515         
00519         double getMinScrX()
00520         {
00521                 return minScrX;
00522         }
00526         double getMinScrY()
00527         {
00528                 return minScrY;
00529         }
00530 
00535         int getClickedX()
00536         {
00537                 return m_clickedX;
00538         }
00539 
00544         int getClickedY()
00545         {
00546                 return m_clickedY;
00547         }
00548         
00553         int getOffsetPixelsX()
00554         {
00555                 return offsetPixelX;
00556         }       
00557         
00562         int getOffsetPixelsY()
00563         {
00564                 return offsetPixelY;
00565         }
00569         void setOffsetPixelX(int offX)
00570         {
00571                 offsetPixelX=offX;
00572         }
00576         void setOffsetPixelY(int offY)
00577         {
00578                 offsetPixelY=offY;
00579         }       
00580         
00584         int getOffsetX()
00585         {
00586                 return offsetX;
00587         }       
00588         
00592         int getOffsetY()
00593         {
00594                 return offsetY;
00595         }
00599         void setOffsetX(int offX)
00600         {
00601                 offsetX=offX;
00602         }
00606         void setOffsetY(int offY)
00607         {
00608                 offsetY=offY;
00609         }       
00610         
00611         /*
00612         * Sets real value of the y-coord for the vertical guide line
00613         * @param newX_realGuide The new value to assing for the vertical guide
00614         */
00615         void setRealGuideX(int newX_realGuide)
00616         {               
00617                 real_guideLine_X = newX_realGuide;      
00618                 if(real_guideLine_X!=-1)
00619                         UpdateAll();
00620         }
00621 
00622         /*
00623         * Gets the real value of the y-coord for the vertical guide line
00624         * @retval real_guideLine_X The assigned value for the vertical guide
00625         */
00626         int getRealGuideX()
00627         {
00628                 return real_guideLine_X;
00629         }       
00630 
00631         /*
00632         * Sets real value of the y-coord for the vertical guide line
00633         * @param newY_realGuide The new value to assing for the vertical guide
00634         */
00635         void setRealGuideY(int newY_realGuide)
00636         {               
00637                 real_guideLine_Y = newY_realGuide;      
00638                 if(real_guideLine_Y!=-1)
00639                         UpdateAll();
00640         }
00641 
00642         /*
00643         * Gets the real value of the y-coord for the vertical guide line
00644         * @retval real_guideLine_Y The assigned value for the vertical guide
00645         */
00646         int getRealGuideY()
00647         {
00648                 return real_guideLine_Y;
00649         }               
00650 
00651         /*
00652         * Sets the condition for drawing or not the guide lines
00653         * @param ifDrawing The new condition to assing 
00654         */
00655         /*void setLineGuidesCondition(bool ifDrawing)
00656         {               
00657                 drawGuides = ifDrawing;         
00658         }
00659         */
00660         
00661         /*
00662         * Gets the condition for drawing or not the guide lines
00663         * @retval drawGuides The assigned condition
00664         */
00665         bool drawGuideLines();
00666 
00667         /*
00668         * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
00669         * event The corresponding event to handle
00670         */
00671         
00672         //void OnGuideLines (wxCommandEvent   &event); 
00673 
00674         //----------------------------------------------------------------------------------
00675         // Previous methods
00676         //----------------------------------------------------------------------------------
00677         
00678         
00685         bool AddLayer( mpLayer* layer);
00686 
00690         void DelLayer( mpLayer* layer);
00691 
00696         double GetScaleX(void) const { return m_scaleX; }
00697 
00702         double GetScaleY(void) const { return m_scaleY; }
00703 
00708         double GetPosX(void) const { return m_posX; }
00709 
00714         double GetPosY(void) const { return m_posY; }
00715 
00722         int GetScrX(void) const { return m_scrX; }
00723 
00730         int GetScrY(void) const { return m_scrY; }
00731         //void SetScrY(int x) const { return m_scrY; }
00732 
00736         void SetScaleX(double scaleX) { if (scaleX!=0) m_scaleX=scaleX; /*UpdateAll();*/ }
00737 
00741         void SetScaleY(double scaleY) { if (scaleY!=0) m_scaleY=scaleY; /*UpdateAll();*/ }
00742 
00746         void SetPosX(double posX) { m_posX=posX; UpdateAll(); }
00747 
00751         void SetPosY(double posY) { m_posY=posY; UpdateAll(); }
00752 
00757         void SetPos( double posX, double posY) { m_posX=posX; m_posY=posY; UpdateAll(); }
00758 
00764         void LockAspect(bool enable = TRUE);
00765 
00770         inline bool IsAspectLocked() { return m_lockaspect; }
00771 
00776         void Fit();
00777 
00779         void ZoomIn();
00780 
00782         void ZoomOut();
00783 
00785         void UpdateAll();
00786 
00787 protected:
00788 
00789         void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
00790         void OnPaint         (wxPaintEvent     &event); 
00791         void OnSize          (wxSizeEvent      &event); 
00792         void OnScroll2       (wxScrollWinEvent &event); 
00793         void OnShowPopupMenu (wxMouseEvent     &event); 
00794         void OnCenter        (wxCommandEvent   &event); 
00795         void OnFit           (wxCommandEvent   &event); 
00796         void OnZoomIn        (wxCommandEvent   &event); 
00797         void OnZoomOut       (wxCommandEvent   &event); 
00798         void OnLockAspect    (wxCommandEvent   &event); 
00799         
00800 
00801         bool UpdateBBox(); 
00802 
00803         wxList m_layers;    
00804         wxMenu m_popmenu;   
00805         bool   m_lockaspect;
00806 
00807         double m_minX;      
00808         double m_maxX;      
00809         double m_minY;      
00810         double m_maxY;      
00811         double m_scaleX;    
00812         double m_scaleY;    
00813         double m_posX;      
00814         double m_posY;      
00815         int    m_scrX;      
00816         int    m_scrY;      
00817         int    m_clickedX;  
00818         int    m_clickedY;  
00819         
00820         //----------------------------------------------
00821         //NEW ATTRIBUTES FOR COMPATIBILITY WITH PPlotter
00822         //----------------------------------------------
00826         int    maxScrX;
00827         
00831         int    maxScrY;
00835         int  minScrX;
00836         
00840         int  minScrY;
00841         /*
00842          the zoom factor
00843          of the zoom
00844         */
00845         float      zoomFactor;
00846 
00847         
00852         int offsetPixelX;
00853         int offsetPixelY;
00854         /*
00855          Offsets in real value according to the actual function
00856         */
00857         int offsetX;
00858         int offsetY;
00859 
00860         /*
00861         * The real value of the y-coord for the horizontal guide line
00862         */
00863         int real_guideLine_X;
00864         /*
00865         * The real value of the y-coord for the vertical guide line
00866         */
00867         int real_guideLine_Y;
00868 
00869         /*
00870         * Represents the condition for drawing or not the line guides, default color is red and assigned to draw them
00871         */
00872         bool drawGuides;
00873         /*
00874          Use to know which type of plotter is
00875          1= default Plotter
00876          2= histogram plotter
00877         */
00878          int type;
00879 
00880  private:
00881         //bitmap of functions
00882         wxBitmap        *_bitmap_functions;
00883 
00884 
00885         DECLARE_CLASS(mpWindow)
00886         DECLARE_EVENT_TABLE()
00887 };
00888 
00889 #endif // _MP_MATHPLOT_H_

Generated on Fri Jun 12 00:08:33 2009 for creaMaracasVisu by  doxygen 1.5.7.1