]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/mathplot.h
dc06a252cfea1761d85d33a6f8a9c048b4f65f4c
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / mathplot.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        mathplot.h
3 // Purpose:     Framework for mathematical graph plotting in wxWindows
4 // Author:      David Schalig
5 // Modified by:
6 // Created:     21/07/2003
7 // Copyright:   (c) David Schalig
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _MP_MATHPLOT_H_
12 #define _MP_MATHPLOT_H_
13 #define ZOOM_FACTOR 1.5
14
15 /* @file mathplot.h */
16 /* @mainpage wxMathPlot
17 wxMathPlot is a framework for mathematical graph plotting in wxWindows.
18
19 The framework is designed for convenience and ease of use.
20
21 @section screenshots Screenshots
22 <a href="screenshots.html">Go to the screenshots page.</a>
23
24 @section overview Overview
25 The heart of wxMathPlot is mpWindow, which is a 2D canvas for plot layers.
26 mpWindow can be embedded as subwindow in a wxPane, a wxFrame, or any other wxWindow.
27 mpWindow provides a zoomable and moveable view of the layers. The current view can
28 be controlled with the mouse, the scrollbars, and a context menu.
29
30 Plot layers are implementations of the abstract base class mpLayer. Those can
31 be function plots, scale rulers, or any other vector data visualisation. wxMathPlot provides
32 two mpLayer implementations for plotting horizontal and vertical rulers: mpScaleX and mpScaleY.
33 For convenient function plotting three more abstract base classes derived from mpLayer
34 are provided: mpFX, mpFY and mpFXY. These base classes already come with plot code, own
35 functions can be implemented by overiding just one member for retrieving a function value.
36
37 @section coding Coding conventions
38 wxMathPlot sticks to wxWindow's coding conventions. All entities defined by wxMathPlot
39 have the prefix <i>mp</i>.
40
41 @section author Author and license
42 wxMathPlot is published under the terms of the wxWindow license.
43 The author David Schalig can be contacted via the wxMathPlot's homepage at
44 http://sourceforge.net/projects/wxmathplot
45 */
46
47 /*
48 #if defined(__GNUG__) && !defined(__APPLE__)
49 #pragma interface "mathplot.h"
50 #endif
51 */
52
53 #include "wx/defs.h"
54 #include <wx/wx.h>
55
56 /*
57 #include "wx/menu.h"
58 #include "wx/scrolwin.h"
59 #include "wx/event.h"
60 #include "wx/dynarray.h"
61 */
62
63 //-----------------------------------------------------------------------------
64 // classes
65 //-----------------------------------------------------------------------------
66
67 class  mpLayer;
68 class  mpFX;
69 class  mpFY;
70 class  mpFXY;
71 class  mpScaleX;
72 class  mpScaleY;
73 class  mpWindow;
74
75 /** Command IDs used by mpWindow */
76 enum
77 {
78         mpID_FIT = 2000,    //!< Fit view to match bounding box of all layers
79         mpID_ZOOM_IN,       //!< Zoom into view at clickposition / window center
80         mpID_ZOOM_OUT,      //!< Zoom out
81         mpID_CENTER,        //!< Center view on click position
82         mpID_LOCKASPECT,    //!< Lock x/y scaling aspect
83         mpID_LINE_GUIDES,       //!< Enables or disables the line guides drawing condition
84 };
85
86 //-----------------------------------------------------------------------------
87 // mpLayer
88 //-----------------------------------------------------------------------------
89
90 /** Plot layer, abstract base class.
91 Any number of mpLayer implementations can be attached to mpWindow.
92 Examples for mpLayer implementations are function graphs, or scale rulers.
93
94 For convenience mpLayer defines a name, a font (wxFont), and a pen (wxPen)
95 as class members. These may or may not be used by implementations.
96 */
97 class  mpLayer : public wxObject
98 {
99 public:
100         mpLayer();
101
102         /** Check whether this layer has a bounding box.
103         The default implementation returns \a TRUE. Overide and return
104         FALSE if your mpLayer implementation should be ignored by the calculation
105         of the global bounding box for all layers in a mpWindow.
106         @retval TRUE Has bounding box
107         @retval FALSE Has not bounding box
108         */
109         virtual bool   HasBBox() { return TRUE; }
110
111         /** Get inclusive left border of bounding box.
112         @return Value
113         */
114         virtual double GetMinX() { return -1.0; }
115
116         /** Get inclusive right border of bounding box.
117         @return Value
118         */
119         virtual double GetMaxX() { return  1.0; }
120
121         /** Get inclusive bottom border of bounding box.
122         @return Value
123         */
124         virtual double GetMinY() { return -1.0; }
125
126         /** Get inclusive top border of bounding box.
127         @return Value
128         */
129         virtual double GetMaxY() { return  1.0; }
130
131         /** Plot given view of layer to the given device context.
132         An implementation of this function has to transform layer coordinates to
133         wxDC coordinates based on the view parameters retrievable from the mpWindow
134         passed in \a w. The passed device context \a dc has its coordinate origin set
135         to the center of the visible area. The coordinate orientation is as show in the
136         following picture:
137         <pre>
138         +--------------------------------------------------+
139         |                                                  |
140         |                                                  |
141         |                (wxDC origin 0,0)                 |
142         |                       x-------------> acending X |
143         |                       |                          |
144         |                       |                          |
145         |                       V ascending Y              |
146         +--------------------------------------------------+
147         </pre>
148         Note that Y ascends in downward direction, whereas the usual vertical orientation
149         for mathematical plots is vice versa. Thus Y-orientation will be swapped usually,
150         when transforming between wxDC and mpLayer coordinates.
151
152         <b> Rules for transformation between mpLayer and wxDC coordinates </b>
153         @code
154         dc_X = (layer_X - mpWindow::GetPosX()) * mpWindow::GetScaleX()
155         dc_Y = (mpWindow::GetPosY() - layer_Y) * mpWindow::GetScaleY() // swapping Y-orientation
156
157         layer_X = (dc_X / mpWindow::GetScaleX()) + mpWindow::GetPosX() // scale guaranted to be not 0
158         layer_Y = mpWindow::GetPosY() - (dc_Y / mpWindow::GetScaleY()) // swapping Y-orientation
159         @endcode
160
161         @param dc Device context to plot to.
162         @param w  View to plot. The visible area can be retrieved from this object.
163         */
164         virtual void   Plot(wxDC & dc, mpWindow & w) = 0;
165
166         /** Get layer name.
167         @return Name
168         */
169         wxString       GetName() const { return m_name; }
170
171         /** Get font set for this layer.
172         @return Font
173         */
174         const wxFont&  GetFont() const { return m_font; }
175
176         /** Get pen set for this layer.
177         @return Pen
178         */
179         const wxPen&   GetPen()  const { return m_pen;  }
180
181         /** Set layer name
182         @param name Name, will be copied to internal class member
183         */
184         void SetName(wxString name) { m_name = name; }
185
186         /** Set layer font
187         @param font Font, will be copied to internal class member
188         */
189         void SetFont(wxFont& font)  { m_font = font; }
190
191         /** Set layer pen
192         @param pen Pen, will be copied to internal class member
193         */
194         void SetPen(wxPen& pen)     { m_pen  = pen;  }
195
196 protected:
197         wxFont   m_font;    //!< Layer's font
198         wxPen    m_pen;     //!< Layer's pen
199         wxString m_name;    //!< Layer's name
200
201         DECLARE_CLASS(mpLayer)
202 };
203
204 //-----------------------------------------------------------------------------
205 // mpLayer implementations - functions
206 //-----------------------------------------------------------------------------
207
208 /** @name Label alignment constants
209 @{*/
210
211 /** @internal */
212 #define mpALIGNMASK    0x03
213 /** Aligns label to the right. For use with mpFX. */
214 #define mpALIGN_RIGHT  0x00
215 /** Aligns label to the center. For use with mpFX and mpFY. */
216 #define mpALIGN_CENTER 0x01
217 /** Aligns label to the left. For use with mpFX. */
218 #define mpALIGN_LEFT   0x02
219 /** Aligns label to the top. For use with mpFY. */
220 #define mpALIGN_TOP    mpALIGN_RIGHT
221 /** Aligns label to the bottom. For use with mpFY. */
222 #define mpALIGN_BOTTOM mpALIGN_LEFT
223 /** Aligns label to north-east. For use with mpFXY. */
224 #define mpALIGN_NE     0x00
225 /** Aligns label to north-west. For use with mpFXY. */
226 #define mpALIGN_NW     0x01
227 /** Aligns label to south-west. For use with mpFXY. */
228 #define mpALIGN_SW     0x02
229 /** Aligns label to south-east. For use with mpFXY. */
230 #define mpALIGN_SE     0x03
231
232 /*@}*/
233
234 /** @name mpLayer implementations - functions
235 @{*/
236
237 /** Abstract base class providing plot and labeling functionality for functions F:X->Y.
238 Override mpFX::GetY to implement a function.
239 Optionally implement a constructor and pass a name (label) and a label alignment
240 to the constructor mpFX::mpFX. If the layer name is empty, no label will be plotted.
241 */
242 class  mpFX : public mpLayer
243 {
244 public:
245         /** @param name  Label
246         @param flags Label alignment, pass one of #mpALIGN_RIGHT, #mpALIGN_CENTER, #mpALIGN_LEFT.
247         */
248         mpFX(wxString name = wxEmptyString, int flags = mpALIGN_RIGHT);
249
250         /** Get function value for argument.
251         Override this function in your implementation.
252         @param x Argument
253         @return Function value
254         */
255         virtual double GetY( double x ) = 0;
256
257         /** Layer plot handler.
258         This implementation will plot the function in the visible area and
259         put a label according to the aligment specified.
260         */
261         virtual void Plot(wxDC & dc, mpWindow & w);
262
263 protected:
264         int m_flags; //!< Holds label alignment
265
266         DECLARE_CLASS(mpFX)
267 };
268
269 /** Abstract base class providing plot and labeling functionality for functions F:Y->X.
270 Override mpFY::GetX to implement a function.
271 Optionally implement a constructor and pass a name (label) and a label alignment
272 to the constructor mpFY::mpFY. If the layer name is empty, no label will be plotted.
273 */
274 class  mpFY : public mpLayer
275 {
276 public:
277         /** @param name  Label
278         @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP.
279         */
280         mpFY(wxString name = wxEmptyString, int flags = mpALIGN_TOP);
281
282         /** Get function value for argument.
283         Override this function in your implementation.
284         @param y Argument
285         @return Function value
286         */
287         virtual double GetX( double y ) = 0;
288
289         /** Layer plot handler.
290         This implementation will plot the function in the visible area and
291         put a label according to the aligment specified.
292         */
293         virtual void Plot(wxDC & dc, mpWindow & w);
294
295 protected:
296         int m_flags; //!< Holds label alignment
297
298         DECLARE_CLASS(mpFY)
299 };
300
301 /** Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
302 Locus argument N is assumed to be in range 0 .. MAX_N, and implicitely derived by enumrating
303 all locus values. Override mpFXY::Rewind and mpFXY::GetNextXY to implement a locus.
304 Optionally implement a constructor and pass a name (label) and a label alignment
305 to the constructor mpFXY::mpFXY. If the layer name is empty, no label will be plotted.
306 */
307 class  mpFXY : public mpLayer
308 {
309 public:
310         /** @param name  Label
311         @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
312         */
313         mpFXY(wxString name = wxEmptyString, int flags = mpALIGN_NE);
314
315         /** Rewind value enumeration with mpFXY::GetNextXY.
316         Override this function in your implementation.
317         */
318         virtual void Rewind() = 0;
319
320         /** Get locus value for next N.
321         Override this function in your implementation.
322         @param x Returns X value
323         @param y Returns Y value
324         */
325         virtual bool GetNextXY(double & x, double & y) = 0;
326
327         /** Layer plot handler.
328         This implementation will plot the locus in the visible area and
329         put a label according to the aligment specified.
330         */
331         virtual void Plot(wxDC & dc, mpWindow & w);
332
333 protected:
334         int m_flags; //!< Holds label alignment
335
336         DECLARE_CLASS(mpFXY)
337 };
338
339 /*@}*/
340
341 //-----------------------------------------------------------------------------
342 // mpLayer implementations - furniture (scales, ...)
343 //-----------------------------------------------------------------------------
344
345 /** @name mpLayer implementations - furniture (scales, ...)
346 @{*/
347
348 /** Plot layer implementing a x-scale ruler.
349 The ruler is fixed at Y=0 in the coordinate system. A label is plottet at
350 the bottom-right hand of the ruler. The scale numbering automatically
351 adjusts to view and zoom factor.
352 */
353 class  mpScaleX : public mpLayer
354 {
355 public:
356         /** @param name Label to plot by the ruler */
357         mpScaleX(wxString name = wxT("X"));
358
359         /** Layer plot handler.
360         This implementation will plot the ruler adjusted to the visible area.
361         */
362         virtual void Plot(wxDC & dc, mpWindow & w);
363
364         /** Check whether this layer has a bounding box.
365         This implementation returns \a FALSE thus making the ruler invisible
366         to the plot layer bounding box calculation by mpWindow.
367         */
368         virtual bool HasBBox() { return FALSE; }
369
370         DECLARE_CLASS(mpScaleX)
371 };
372
373 /** Plot layer implementing a y-scale ruler.
374 The ruler is fixed at X=0 in the coordinate system. A label is plottet at
375 the top-right hand of the ruler. The scale numbering automatically
376 adjusts to view and zoom factor.
377 */
378 class  mpScaleY : public mpLayer
379 {
380 public:
381         /** @param name Label to plot by the ruler */
382         mpScaleY(wxString name = wxT("Y"));
383
384         /** Layer plot handler.
385         This implementation will plot the ruler adjusted to the visible area.
386         */
387         virtual void Plot(wxDC & dc, mpWindow & w);
388
389         /** Check whether this layer has a bounding box.
390         This implementation returns \a FALSE thus making the ruler invisible
391         to the plot layer bounding box calculation by mpWindow.
392         */
393         virtual bool HasBBox() { return FALSE; }
394
395 protected:
396
397         DECLARE_CLASS(mpScaleY)
398 };
399
400 //-----------------------------------------------------------------------------
401 // mpWindow
402 //-----------------------------------------------------------------------------
403
404 /** @name Constants defining mouse modes for mpWindow
405 @{*/
406
407 /** Mouse panning drags the view. Mouse mode for mpWindow. */
408 #define mpMOUSEMODE_DRAG    0
409 /** Mouse panning creates a zoom box. Mouse mode for mpWindow. */
410 #define mpMOUSEMODE_ZOOMBOX 1
411
412 /*@}*/
413
414 /** Canvas for plotting mpLayer implementations.
415
416 This class defines a zoomable and moveable 2D plot canvas. Any number
417 of mpLayer implementations (scale rulers, function plots, ...) can be
418 attached using mpWindow::AddLayer.
419
420 The canvas window provides a context menu with actions for navigating the view.
421 The context menu can be retrieved with mpWindow::GetPopupMenu, e.g. for extending it
422 externally.
423 */
424 class  mpWindow : public wxScrolledWindow
425 {
426 public:
427         mpWindow() {}
428         mpWindow( wxWindow *parent, wxWindowID id,
429                 const wxPoint &pos = wxDefaultPosition, 
430                 const wxSize &size = wxDefaultSize,
431                 int flags = 0);
432         ~mpWindow();
433
434         /** Get reference to context menu of the plot canvas.
435         @return Pointer to menu. The menu can be modified.
436         */
437         wxMenu* GetPopupMenu() { return &m_popmenu; }
438
439         //-----------------------
440         // new methods for plotter
441         //-----------------------
442         /*
443          Set Type
444         */
445         void setType(int t)
446         {
447                 type=t;
448         }
449         /*
450          Get Type
451         */
452         int getType()
453         {
454                 return type;
455         }
456                 
457         
458         /**
459          set the max value in the x axis
460          @param maxX 
461         */
462         void setMaxScrX(int maxX)
463         {
464                 maxScrX=maxX;
465         }
466         /**
467          set the max value in the y axis
468          @param maxY
469         */
470         void setMaxScrY(int maxY)
471         {
472                 maxScrY=maxY;
473         }
474         
475         
476         /**Get maximum value in x
477          @return maxScrX
478         */
479         double getMaxScrX()
480         {
481                 return maxScrX;
482         }
483         /**Get maximum value in y
484          @return maxScrY
485         */
486         double getMaxScrY()
487         {
488                 return maxScrY;
489         }
490         /*
491          returns the zoomFactor
492         */
493         float getZoomFactor()
494         {
495                 return zoomFactor;
496         }
497         /**
498          set the min value in the x axis
499          @param minX 
500         */
501         void setMinScrX(int minX)
502         {
503                 minScrX=minX;
504         }
505         /**
506          set the min value in the y axis
507          @param minY
508         */
509         void setMinScrY(int minY)
510         {
511                 minScrY=minY;
512         }
513         
514         
515         /**Get miniimum value in x
516          @return minScrX
517         */
518         double getMinScrX()
519         {
520                 return minScrX;
521         }
522         /**Get minimum value in y
523          @return minScrY
524         */
525         double getMinScrY()
526         {
527                 return minScrY;
528         }
529
530         /**
531         Get the x-clicked by the user
532         @return m_clickedX
533         */
534         int getClickedX()
535         {
536                 return m_clickedX;
537         }
538
539         /**
540         Get the y-clicked by the user
541         @return m_clickedY
542         */
543         int getClickedY()
544         {
545                 return m_clickedY;
546         }
547         
548         /**
549         Gets the x-offset of the zoom
550         in pixels
551         */
552         int getOffsetPixelsX()
553         {
554                 return offsetPixelX;
555         }       
556         
557         /**
558         Gets the offset of the zoom
559         in pixels
560         */
561         int getOffsetPixelsY()
562         {
563                 return offsetPixelY;
564         }
565         /**
566          Set the x-offset of the zoom
567         */
568         void setOffsetPixelX(int offX)
569         {
570                 offsetPixelX=offX;
571         }
572         /**
573          Set the y-offset of the zoom
574         */
575         void setOffsetPixelY(int offY)
576         {
577                 offsetPixelY=offY;
578         }       
579         
580         /**
581         Gets the x-offset of the zoom
582         */
583         int getOffsetX()
584         {
585                 return offsetX;
586         }       
587         
588         /**
589         Gets the offset of the zoom
590         */
591         int getOffsetY()
592         {
593                 return offsetY;
594         }
595         /**
596          Set the x-offset of the zoom
597         */
598         void setOffsetX(int offX)
599         {
600                 offsetX=offX;
601         }
602         /**
603          Set the y-offset of the zoom
604         */
605         void setOffsetY(int offY)
606         {
607                 offsetY=offY;
608         }       
609         
610         /*
611         * Sets real value of the y-coord for the vertical guide line
612         * @param newX_realGuide The new value to assing for the vertical guide
613         */
614         void setRealGuideX(int newX_realGuide)
615         {               
616                 real_guideLine_X = newX_realGuide;      
617                 if(real_guideLine_X!=-1)
618                         UpdateAll();
619         }
620
621         /*
622         * Gets the real value of the y-coord for the vertical guide line
623         * @retval real_guideLine_X The assigned value for the vertical guide
624         */
625         int getRealGuideX()
626         {
627                 return real_guideLine_X;
628         }       
629
630         /*
631         * Sets real value of the y-coord for the vertical guide line
632         * @param newY_realGuide The new value to assing for the vertical guide
633         */
634         void setRealGuideY(int newY_realGuide)
635         {               
636                 real_guideLine_Y = newY_realGuide;      
637                 if(real_guideLine_Y!=-1)
638                         UpdateAll();
639         }
640
641         /*
642         * Gets the real value of the y-coord for the vertical guide line
643         * @retval real_guideLine_Y The assigned value for the vertical guide
644         */
645         int getRealGuideY()
646         {
647                 return real_guideLine_Y;
648         }               
649
650         /*
651         * Sets the condition for drawing or not the guide lines
652         * @param ifDrawing The new condition to assing 
653         */
654         /*void setLineGuidesCondition(bool ifDrawing)
655         {               
656                 drawGuides = ifDrawing;         
657         }
658
659         /*
660         * Gets the condition for drawing or not the guide lines
661         * @retval drawGuides The assigned condition
662         */
663         bool drawGuideLines();
664
665         /*
666         * Guide lines menu handler method that reacts to the mpID_LINE_GUIDES cimmand event
667         * event The corresponding event to handle
668         */
669         
670         //void OnGuideLines (wxCommandEvent   &event); 
671
672         //----------------------------------------------------------------------------------
673         // Previous methods
674         //----------------------------------------------------------------------------------
675         
676         
677         /** Add a plot layer to the canvas.
678         @param layer Pointer to layer. The mpLayer object will get under control of mpWindow,
679         i.e. it will be delete'd on mpWindow destruction
680         @retval TRUE Success
681         @retval FALSE Failure due to out of memory.
682         */
683         bool AddLayer( mpLayer* layer);
684
685         /** Remove a plot layer from the canvas.
686         @param layer Pointer to layer. The mpLayer object will be destructed using delete.
687         */
688         void DelLayer( mpLayer* layer);
689
690         /** Get current view's X scale.
691         See @ref mpLayer::Plot "rules for coordinate transformation"
692         @return Scale
693         */
694         double GetScaleX(void) const { return m_scaleX; }
695
696         /** Get current view's Y scale.
697         See @ref mpLayer::Plot "rules for coordinate transformation"
698         @return Scale
699         */
700         double GetScaleY(void) const { return m_scaleY; }
701
702         /** Get current view's X position.
703         See @ref mpLayer::Plot "rules for coordinate transformation"
704         @return X Position in layer coordinate system, that corresponds to the center point of the view.
705         */
706         double GetPosX(void) const { return m_posX; }
707
708         /** Get current view's Y position.
709         See @ref mpLayer::Plot "rules for coordinate transformation"
710         @return Y Position in layer coordinate system, that corresponds to the center point of the view.
711         */
712         double GetPosY(void) const { return m_posY; }
713
714         /** Get current view's X dimension in device context units.
715         Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
716         implementations should rely on the value returned by the function.
717         See @ref mpLayer::Plot "rules for coordinate transformation"
718         @return X dimension. 
719         */
720         int GetScrX(void) const { return m_scrX; }
721
722         /** Get current view's Y dimension in device context units.
723         Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
724         implementations should rely on the value returned by the function.
725         See @ref mpLayer::Plot "rules for coordinate transformation"
726         @return Y dimension. 
727         */
728         int GetScrY(void) const { return m_scrY; }
729         //void SetScrY(int x) const { return m_scrY; }
730
731         /** Set current view's X scale and refresh display. 
732         @param scaleX New scale, must not be 0.
733         */
734         void SetScaleX(double scaleX) { if (scaleX!=0) m_scaleX=scaleX; /*UpdateAll();*/ }
735
736         /** Set current view's Y scale and refresh display. 
737         @param scaleY New scale, must not be 0.
738         */
739         void SetScaleY(double scaleY) { if (scaleY!=0) m_scaleY=scaleY; /*UpdateAll();*/ }
740
741         /** Set current view's X position and refresh display. 
742         @param posX New position that corresponds to the center point of the view.
743         */
744         void SetPosX(double posX) { m_posX=posX; UpdateAll(); }
745
746         /** Set current view's Y position and refresh display. 
747         @param posY New position that corresponds to the center point of the view.
748         */
749         void SetPosY(double posY) { m_posY=posY; UpdateAll(); }
750
751         /** Set current view's X and Y position and refresh display. 
752         @param posX New position that corresponds to the center point of the view.
753         @param posY New position that corresponds to the center point of the view.
754         */
755         void SetPos( double posX, double posY) { m_posX=posX; m_posY=posY; UpdateAll(); }
756
757         /** Enable or disable X/Y scale aspect locking for the view.
758         @note Explicit calls to mpWindow::SetScaleX and mpWindow::SetScaleY will set
759         an unlocked apect, but any other action changing the view scale will
760         lock the aspect again.
761         */
762         void LockAspect(bool enable = TRUE);
763
764         /** Checks whether the X/Y scale aspect is locked.
765         @retval TRUE Locked
766         @retval FALSE Unlocked
767         */
768         inline bool IsAspectLocked() { return m_lockaspect; }
769
770         /** Set view to fit global bounding box of all plot layers and refresh display.
771         Scale and position will be set to a show all attached mpLayers.
772         The X/Y scale aspect lock is taken into account.
773         */
774         void Fit();
775
776         /** Zoom into current view and refresh display */
777         void ZoomIn();
778
779         /** Zoom out current view and refresh display */
780         void ZoomOut();
781
782         /** Refresh display */
783         void UpdateAll();
784
785 protected:
786
787         void Refresh(bool eraseBackground = true, const wxRect* rect = NULL);
788         void OnPaint         (wxPaintEvent     &event); //!< Paint handler, will plot all attached layers
789         void OnSize          (wxSizeEvent      &event); //!< Size handler, will update scroll bar sizes
790         void OnScroll2       (wxScrollWinEvent &event); //!< Scroll handler, will move canvas
791         void OnShowPopupMenu (wxMouseEvent     &event); //!< Mouse handler, will show context menu
792         void OnCenter        (wxCommandEvent   &event); //!< Context menu handler
793         void OnFit           (wxCommandEvent   &event); //!< Context menu handler
794         void OnZoomIn        (wxCommandEvent   &event); //!< Context menu handler
795         void OnZoomOut       (wxCommandEvent   &event); //!< Context menu handler
796         void OnLockAspect    (wxCommandEvent   &event); //!< Context menu handler
797         
798
799         bool UpdateBBox(); //!< Recalculate global layer bounding box
800
801         wxList m_layers;    //!< List of attached plot layers
802         wxMenu m_popmenu;   //!< Canvas' context menu
803         bool   m_lockaspect;//!< Scale aspect is locked or not
804
805         double m_minX;      //!< Global layer bounding box, left border incl.
806         double m_maxX;      //!< Global layer bounding box, right border incl.
807         double m_minY;      //!< Global layer bounding box, bottom border incl.
808         double m_maxY;      //!< Global layer bounding box, top border incl.
809         double m_scaleX;    //!< Current view's X scale
810         double m_scaleY;    //!< Current view's Y scale
811         double m_posX;      //!< Current view's X position
812         double m_posY;      //!< Current view's Y position
813         int    m_scrX;      //!< Current view's X dimension
814         int    m_scrY;      //!< Current view's Y dimension
815         int    m_clickedX;  //!< Last mouse click X position, for centering and zooming the view
816         int    m_clickedY;  //!< Last mouse click Y position, for centering and zooming the view
817         
818         //----------------------------------------------
819         //NEW ATTRIBUTES FOR COMPATIBILITY WITH PPlotter
820         //----------------------------------------------
821         /**
822          the max value in the x axis
823         */
824         int    maxScrX;
825         
826         /**
827          the max value in the y axis
828         */
829         int    maxScrY;
830         /**
831          the min value in the x axis
832         */
833         int  minScrX;
834         
835         /**
836          the min value in the y axis
837         */
838         int  minScrY;
839         /*
840          the zoom factor
841          of the zoom
842         */
843         float      zoomFactor;
844
845         
846         /**
847          offset in pixels where the user has clicked
848          before changing the scale (in the actual function)
849         */
850         int offsetPixelX;
851         int offsetPixelY;
852         /*
853          Offsets in real value according to the actual function
854         */
855         int offsetX;
856         int offsetY;
857
858         /*
859         * The real value of the y-coord for the horizontal guide line
860         */
861         int real_guideLine_X;
862         /*
863         * The real value of the y-coord for the vertical guide line
864         */
865         int real_guideLine_Y;
866
867         /*
868         * Represents the condition for drawing or not the line guides, default color is red and assigned to draw them
869         */
870         bool drawGuides;
871         /*
872          Use to know which type of plotter is
873          1= default Plotter
874          2= histogram plotter
875         */
876          int type;
877
878  private:
879         //bitmap of functions
880         wxBitmap        *_bitmap_functions;
881
882
883         DECLARE_CLASS(mpWindow)
884         DECLARE_EVENT_TABLE()
885 };
886
887 #endif // _MP_MATHPLOT_H_