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