KiCad PCB EDA Suite
Loading...
Searching...
No Matches
mathplot.h
Go to the documentation of this file.
1
2// Name: mathplot.cpp
3// Purpose: Framework for plotting in wxWindows
4// Original Author: David Schalig
5// Maintainer: Davide Rondini
6// Contributors: Jose Luis Blanco, Val Greene, Maciej Suminski, Tomasz Wlostowski
7// Created: 21/07/2003
8// Last edit: 05/08/2016
9// Copyright: (c) David Schalig, Davide Rondini
10// Licence: wxWindows licence
12
13#ifndef _MP_MATHPLOT_H_
14#define _MP_MATHPLOT_H_
15
58// this definition uses windows dll to export function.
59// WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
60// mathplot_EXPORTS will be defined by cmake
61#ifdef mathplot_EXPORTS
62#define WXDLLIMPEXP_MATHPLOT WXEXPORT
63#define WXDLLIMPEXP_DATA_MATHPLOT( type ) WXEXPORT type
64#else // not making DLL
65#define WXDLLIMPEXP_MATHPLOT
66#define WXDLLIMPEXP_DATA_MATHPLOT( type ) type
67#endif
68
69#include <vector>
70
71#include <wx/defs.h>
72#include <wx/menu.h>
73#include <wx/scrolwin.h>
74#include <wx/event.h>
75#include <wx/dynarray.h>
76#include <wx/pen.h>
77#include <wx/dcmemory.h>
78#include <wx/string.h>
79#include <wx/print.h>
80#include <wx/image.h>
81
82
83#include <deque>
84
85#include <algorithm>
86
87// For memory leak debug
88#ifdef _WINDOWS
89#ifdef _DEBUG
90#include <crtdbg.h>
91#define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
92#else
93#define DEBUG_NEW new
94#endif // _DEBUG
95#endif // _WINDOWS
96
97// Separation for axes when set close to border
98#define X_BORDER_SEPARATION 40
99#define Y_BORDER_SEPARATION 60
100
101// -----------------------------------------------------------------------------
102// classes
103// -----------------------------------------------------------------------------
104
114
116enum
117{
118 mpID_FIT = 2000, // !< Fit view to match bounding box of all layers
119 mpID_ZOOM_IN, // !< Zoom into view at clickposition / window center
120 mpID_ZOOM_OUT, // !< Zoom out
121 mpID_CENTER, // !< Center view on click position
122};
123
124// -----------------------------------------------------------------------------
125// mpLayer
126// -----------------------------------------------------------------------------
127
128typedef enum __mp_Layer_Type
129{
130 mpLAYER_UNDEF, // !< Layer type undefined
131 mpLAYER_AXIS, // !< Axis type layer
132 mpLAYER_PLOT, // !< Plot type layer
133 mpLAYER_INFO, // !< Info box type layer
134 mpLAYER_BITMAP // !< Bitmap type layer
136
147class mpScaleBase;
148
149class WXDLLIMPEXP_MATHPLOT mpLayer : public wxObject
150{
151public:
152 mpLayer();
153
154 virtual ~mpLayer() {};
155
163 virtual bool HasBBox() const { return true; }
164
172 virtual bool IsInfo() const { return false; };
173
177 virtual double GetMinX() const { return -1.0; }
178
182 virtual double GetMaxX() const { return 1.0; }
183
187 virtual double GetMinY() const { return -1.0; }
188
192 virtual double GetMaxY() const { return 1.0; }
193
235 virtual void Plot( wxDC& dc, mpWindow& w ) = 0;
236
240 const wxString& GetName() const { return m_name; }
241
242 const wxString& GetDisplayName() const
243 {
244 return m_displayName.IsEmpty() ? m_name : m_displayName;
245 }
246
250 const wxFont& GetFont() const { return m_font; }
251
255 const wxPen& GetPen() const { return m_pen; }
256
260 void SetContinuity( bool continuity ) { m_continuous = continuity; }
261
265 bool GetContinuity() const { return m_continuous; }
266
269 void ShowName( bool show ) { m_showName = show; };
270
274 virtual void SetName( const wxString& name ) { m_name = name; }
275
279 void SetFont( const wxFont& font ) { m_font = font; }
280
284 void SetPen( const wxPen& pen ) { m_pen = pen; }
285
288 mpLayerType GetLayerType() const { return m_type; };
289
292 bool IsVisible() const { return m_visible; };
293
296 void SetVisible( bool show ) { m_visible = show; };
297
300 const wxBrush& GetBrush() const { return m_brush; };
301
304 void SetBrush( const wxBrush& brush ) { m_brush = brush; };
305
306protected:
307
308 wxFont m_font; // !< Layer's font
309 wxPen m_pen; // !< Layer's pen
310 wxBrush m_brush; // !< Layer's brush
311 wxString m_name; // !< Layer's name
313 bool m_continuous; // !< Specify if the layer will be plotted as a continuous line or a set of points.
314 bool m_showName; // !< States whether the name of the layer must be shown (default is true).
315 mpLayerType m_type; // !< Define layer type, which is assigned by constructor
316 bool m_visible; // !< Toggles layer visibility
317
318 DECLARE_DYNAMIC_CLASS( mpLayer )
319};
320
321
322// -----------------------------------------------------------------------------
323// mpInfoLayer
324// -----------------------------------------------------------------------------
325
331{
332public:
334 mpInfoLayer();
335
339 mpInfoLayer( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
340
342 virtual ~mpInfoLayer();
343
346 virtual bool HasBBox() const override { return false; }
347
352 virtual void Plot( wxDC& dc, mpWindow& w ) override;
353
357 virtual bool IsInfo() const override { return true; }
358
362 virtual bool Inside( const wxPoint& point ) const;
363
366 virtual void Move( wxPoint delta );
367
369 virtual void UpdateReference();
370
373 wxPoint GetPosition() const;
374
377 wxSize GetSize() const;
378
379protected:
380 wxRect m_dim; // !< The bounding rectangle of the box. It may be resized dynamically
381 // by the Plot method.
382 wxPoint m_reference; // !< Holds the reference point for movements
383 wxBrush m_brush; // !< The brush to be used for the background
384 int m_winX; // !< Holds the mpWindow size. Used to rescale position when window is
385 int m_winY; // resized.
386
387 DECLARE_DYNAMIC_CLASS( mpInfoLayer )
388};
389
394{
395public:
397 mpInfoLegend();
398
403 mpInfoLegend( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
404
407
412 virtual void Plot( wxDC& dc, mpWindow& w ) override;
413
414protected:
415};
416
417
418// -----------------------------------------------------------------------------
419// mpLayer implementations - functions
420// -----------------------------------------------------------------------------
421
426#define mpALIGNMASK 0x03
428#define mpALIGN_RIGHT 0x00
430#define mpALIGN_CENTER 0x01
432#define mpALIGN_LEFT 0x02
434#define mpALIGN_TOP mpALIGN_RIGHT
436#define mpALIGN_BOTTOM mpALIGN_LEFT
438#define mpALIGN_BORDER_BOTTOM 0x04
440#define mpALIGN_BORDER_TOP 0x05
442#define mpALIGN_FAR_RIGHT 0x06
444#define mpX_NORMAL 0x00
446#define mpX_TIME 0x01
448#define mpX_HOURS 0x02
450#define mpX_DATE 0x03
452#define mpX_DATETIME 0x04
454#define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
456#define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
458#define mpALIGN_NE 0x00
460#define mpALIGN_NW 0x01
462#define mpALIGN_SW 0x02
464#define mpALIGN_SE 0x03
465
477{
478public:
482 mpFX( const wxString& name = wxEmptyString, int flags = mpALIGN_RIGHT );
483
489 virtual double GetY( double x ) const = 0;
490
495 virtual void Plot( wxDC& dc, mpWindow& w ) override;
496
497protected:
498 int m_flags; // !< Holds label alignment
499
500 DECLARE_DYNAMIC_CLASS( mpFX )
501};
502
509{
510public:
514 mpFY( const wxString& name = wxEmptyString, int flags = mpALIGN_TOP );
515
521 virtual double GetX( double y ) const = 0;
522
527 virtual void Plot( wxDC& dc, mpWindow& w ) override;
528
529protected:
530 int m_flags; // !< Holds label alignment
531
532 DECLARE_DYNAMIC_CLASS( mpFY )
533};
534
543{
544public:
548 mpFXY( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
549
553 virtual void Rewind() = 0;
554
560 virtual bool GetNextXY( double& x, double& y ) = 0;
561
562 virtual size_t GetCount() const = 0;
563
568 virtual void Plot( wxDC& dc, mpWindow& w ) override;
569
570 virtual void SetScale( mpScaleBase* scaleX, mpScaleBase* scaleY );
571
572 void UpdateScales();
573
574 double s2x( double plotCoordX ) const;
575 double s2y( double plotCoordY ) const;
576
577 double x2s( double x ) const;
578 double y2s( double y ) const;
579
580protected:
581 int m_flags; // !< Holds label alignment
582
583 // Data to calculate label positioning
584 wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
585 // int drawnPoints;
586 mpScaleBase* m_scaleX, * m_scaleY;
587
592 void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
593
594 DECLARE_DYNAMIC_CLASS( mpFXY )
595};
596
599// -----------------------------------------------------------------------------
600// mpLayer implementations - furniture (scales, ...)
601// -----------------------------------------------------------------------------
602
613{
614public:
615 mpScaleBase();
616 virtual ~mpScaleBase() {};
617
618 virtual bool IsHorizontal() const = 0;
619
620 bool HasBBox() const override { return false; }
621
626 void SetAlign( int align ) { m_flags = align; };
627
628 void SetNameAlign( int align ) { m_nameFlags = align; }
629
633 void SetTicks( bool enable ) { m_ticks = enable; };
634
638 bool GetTicks() const { return m_ticks; };
639
640 void GetDataRange( double& minV, double& maxV ) const
641 {
642 minV = m_minV;
643 maxV = m_maxV;
644 }
645
646 virtual void ExtendDataRange( double minV, double maxV )
647 {
648 if( !m_rangeSet )
649 {
650 m_minV = minV;
651 m_maxV = maxV;
652 m_rangeSet = true;
653 }
654 else
655 {
656 m_minV = std::min( minV, m_minV );
657 m_maxV = std::max( maxV, m_maxV );
658 }
659
660 if( m_minV == m_maxV )
661 {
662 m_minV = m_minV - 1.0;
663 m_maxV = m_maxV + 1.0;
664 }
665 }
666
667 virtual void ResetDataRange()
668 {
669 m_rangeSet = false;
670 }
671
672 double AbsMaxValue() const
673 {
674 return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
675 }
676
677 double AbsVisibleMaxValue() const
678 {
679 return m_absVisibleMaxV;
680 }
681
682 void SetAxisMinMax( bool lock, double minV, double maxV )
683 {
684 m_axisLocked = lock;
685 m_axisMin = minV;
686 m_axisMax = maxV;
687 }
688
689 bool GetAxisMinMax( double* minV, double* maxV )
690 {
691 if( m_axisLocked )
692 {
693 *minV = m_axisMin;
694 *maxV = m_axisMax;
695 }
696 else if( !m_tickValues.empty() )
697 {
698 *minV = m_tickValues.front();
699 *maxV = m_tickValues.back();
700 }
701
702 return m_axisLocked;
703 }
704
705 virtual double TransformToPlot( double x ) const { return 0.0; };
706 virtual double TransformFromPlot( double xplot ) const { return 0.0; };
707
709 {
710 TICK_LABEL( double pos_ = 0.0, const wxString& label_ = wxT( "" ) ) :
711 pos( pos_ ),
712 label( label_ ),
713 visible( true )
714 {}
715
716 double pos;
717 wxString label;
719 };
720
721protected:
722
723 void updateTickLabels( wxDC& dc, mpWindow& w );
724 void computeLabelExtents( wxDC& dc, mpWindow& w );
725
726 // virtual int getLabelDecimalDigits(int maxDigits) const;
727 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) {};
728 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) {};
729
730 virtual void formatLabels() {};
731
732protected:
733 std::vector<double> m_tickValues;
734 std::vector<TICK_LABEL> m_tickLabels;
735
736 double m_offset, m_scale;
738 int m_flags; // !< Flag for axis alignment
740 bool m_ticks; // !< Flag to toggle between ticks or grid
741 double m_minV, m_maxV;
744 double m_axisMin;
745 double m_axisMax;
748};
749
751{
752public:
760 mpScaleXBase( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true,
761 unsigned int type = mpX_NORMAL );
762 virtual ~mpScaleXBase() {};
763
764 virtual bool IsHorizontal() const override { return true; }
765 virtual void Plot( wxDC& dc, mpWindow& w ) override;
766
767 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
768
769 DECLARE_DYNAMIC_CLASS( mpScaleXBase )
770};
771
772
774{
775public:
783 mpScaleX( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true,
784 unsigned int type = mpX_NORMAL );
785
786 virtual double TransformToPlot( double x ) const override;
787 virtual double TransformFromPlot( double xplot ) const override;
788
789protected:
790 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
791
792 DECLARE_DYNAMIC_CLASS( mpScaleX )
793};
794
795
797{
798public:
806 mpScaleXLog( const wxString& name = wxT( "log(X)" ), int flags = mpALIGN_CENTER,
807 bool ticks = true, unsigned int type = mpX_NORMAL );
808
809 virtual double TransformToPlot( double x ) const override;
810 virtual double TransformFromPlot( double xplot ) const override;
811
812protected:
813 void recalculateTicks( wxDC& dc, mpWindow& w ) override;
814
815 DECLARE_DYNAMIC_CLASS( mpScaleXLog )
816};
817
818
827{
828public:
834 mpScaleY( const wxString& name = wxT( "Y" ), int flags = mpALIGN_CENTER, bool ticks = true );
835
836 virtual bool IsHorizontal() const override { return false; }
837
841 virtual void Plot( wxDC& dc, mpWindow& w ) override;
842
847 virtual bool HasBBox() const override { return false; }
848
849 virtual double TransformToPlot( double x ) const override;
850 virtual double TransformFromPlot( double xplot ) const override;
851
852 void SetMasterScale( mpScaleY* masterScale ) { m_masterScale = masterScale; }
853
854protected:
855 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
856 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
857
858 void computeSlaveTicks( mpWindow& w );
859
861 int m_flags; // !< Flag for axis alignment
862 bool m_ticks; // !< Flag to toggle between ticks or grid
863
864 DECLARE_DYNAMIC_CLASS( mpScaleY )
865};
866
867// -----------------------------------------------------------------------------
868// mpWindow
869// -----------------------------------------------------------------------------
870
875#define mpMOUSEMODE_DRAG 0
877#define mpMOUSEMODE_ZOOMBOX 1
878
881// WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, wxLayerList );
882typedef std::deque<mpLayer*> wxLayerList;
883
906class WXDLLIMPEXP_MATHPLOT mpWindow : public wxWindow
907{
908public:
909 mpWindow();
910 mpWindow( wxWindow* parent, wxWindowID id );
911 ~mpWindow();
912
916 wxMenu* GetPopupMenu() { return &m_popmenu; }
917
926 bool AddLayer( mpLayer* layer, bool refreshDisplay = true );
927
938 bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true );
939
946 void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true );
947
948
954 mpLayer* GetLayer( int position ) const;
955
960 const mpLayer* GetLayerByName( const wxString& name ) const;
961 mpLayer* GetLayerByName( const wxString& name )
962 {
963 return const_cast<mpLayer*>( static_cast<const mpWindow*>( this )->GetLayerByName( name ) );
964 }
965
970 double GetScaleX() const { return m_scaleX; };
971
976 double GetScaleY() const { return m_scaleY; }
977
982 double GetPosX() const { return m_posX; }
983
988 double GetPosY() const { return m_posY; }
989
996 int GetScrX() const { return m_scrX; }
997 int GetXScreen() const { return m_scrX; }
998
1005 int GetScrY() const { return m_scrY; }
1006 int GetYScreen() const { return m_scrY; }
1007
1011 void SetScaleX( double scaleX );
1012
1016 void SetScaleY( double scaleY )
1017 {
1018 if( scaleY != 0 )
1019 m_scaleY = scaleY;
1020
1021 UpdateAll();
1022 }
1023
1027 void SetPosX( double posX ) { m_posX = posX; UpdateAll(); }
1028
1032 void SetPosY( double posY ) { m_posY = posY; UpdateAll(); }
1033
1038 void SetPos( double posX, double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
1039
1045 void SetScr( int scrX, int scrY ) { m_scrX = scrX; m_scrY = scrY; }
1046
1049 inline double p2x( wxCoord pixelCoordX ) { return m_posX + pixelCoordX / m_scaleX; }
1050
1053 inline double p2y( wxCoord pixelCoordY ) { return m_posY - pixelCoordY / m_scaleY; }
1054
1057 inline wxCoord x2p( double x ) { return (wxCoord) ( (x - m_posX) * m_scaleX ); }
1058
1061 inline wxCoord y2p( double y ) { return (wxCoord) ( (m_posY - y) * m_scaleY ); }
1062
1063
1066 void EnableDoubleBuffer( bool enabled ) { m_enableDoubleBuffer = enabled; }
1067
1070 void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
1071
1074 void EnableMouseWheelPan( bool enabled ) { m_enableMouseWheelPan = enabled; }
1075
1080 void Fit() override;
1081
1088 void Fit( double xMin, double xMax, double yMin, double yMax,
1089 const wxCoord* printSizeX = nullptr, const wxCoord* printSizeY = nullptr );
1090
1095 void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
1096 void ZoomIn( const wxPoint& centerPoint, double zoomFactor );
1097
1102 void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
1103 void ZoomOut( const wxPoint& centerPoint, double zoomFactor );
1104
1107 void ZoomRect( wxPoint p0, wxPoint p1 );
1108
1110 void UpdateAll();
1111
1112 // Added methods by Davide Rondini
1113
1116 unsigned int CountAllLayers() const { return m_layers.size(); };
1117
1122 double GetDesiredXmin() const { return m_desiredXmin; }
1123
1128 double GetDesiredXmax() const { return m_desiredXmax; }
1129
1134 double GetDesiredYmin() const { return m_desiredYmin; }
1135
1140 double GetDesiredYmax() const { return m_desiredYmax; }
1141
1145 void GetBoundingBox( double* bbox ) const;
1146
1152 bool SaveScreenshot( const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_BMP,
1153 wxSize imageSize = wxDefaultSize, bool fit = false );
1154
1160
1167 void SetMargins( int top, int right, int bottom, int left );
1168
1170 void SetMarginTop( int top ) { m_marginTop = top; };
1172 void SetMarginRight( int right ) { m_marginRight = right; };
1174 void SetMarginBottom( int bottom ) { m_marginBottom = bottom; };
1176 void SetMarginLeft( int left ) { m_marginLeft = left; };
1177
1179 int GetMarginTop() const { return m_marginTop; };
1181 int GetMarginRight() const { return m_marginRight; };
1183 int GetMarginBottom() const { return m_marginBottom; };
1185 int GetMarginLeft() const { return m_marginLeft; };
1186
1190 mpInfoLayer* IsInsideInfoLayer( wxPoint& point );
1191
1195 void SetLayerVisible( const wxString& name, bool viewable );
1196
1200 bool IsLayerVisible( const wxString& name ) const;
1201
1205 void SetLayerVisible( const unsigned int position, bool viewable );
1206
1210 bool IsLayerVisible( unsigned int position ) const;
1211
1216 void SetColourTheme( const wxColour& bgColour, const wxColour& drawColour,
1217 const wxColour& axesColour );
1218
1221 const wxColour& GetAxesColour() { return m_axColour; };
1222
1224 void LimitView( bool aEnable )
1225 {
1226 m_enableLimitedView = aEnable;
1227 }
1228
1229 void LockY( bool aLock ) { m_yLocked = aLock; }
1230 bool GetYLocked() const { return m_yLocked; }
1231
1232 void AdjustLimitedView();
1233
1234protected:
1235 void OnPaint( wxPaintEvent& event ); // !< Paint handler, will plot all attached layers
1236 void OnSize( wxSizeEvent& event ); // !< Size handler, will update scroll bar sizes
1237
1238 void OnShowPopupMenu( wxMouseEvent& event ); // !< Mouse handler, will show context menu
1239 void OnMouseMiddleDown( wxMouseEvent& event ); // !< Mouse handler, for detecting when the user
1240
1241 // !< drags with the middle button or just "clicks" for the menu
1242 void OnCenter( wxCommandEvent& event ); // !< Context menu handler
1243 void OnFit( wxCommandEvent& event ); // !< Context menu handler
1244 void OnZoomIn( wxCommandEvent& event ); // !< Context menu handler
1245 void OnZoomOut( wxCommandEvent& event ); // !< Context menu handler
1246 void OnMouseWheel( wxMouseEvent& event ); // !< Mouse handler for the wheel
1247 void OnMagnify( wxMouseEvent& event ); // !< Pinch zoom handler
1248 void OnMouseMove( wxMouseEvent& event ); // !< Mouse handler for mouse motion (for pan)
1249 void OnMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
1250 void OnMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
1251
1252 bool CheckXLimits( double& desiredMax, double& desiredMin ) const
1253 {
1254 return !( m_enableLimitedView
1255 && (desiredMax > m_maxX - m_marginRight / m_scaleX
1256 || desiredMin < m_minX - m_marginLeft / m_scaleX) );
1257 }
1258
1259 bool CheckYLimits( double& desiredMax, double& desiredMin ) const
1260 {
1261 return !( m_enableLimitedView
1262 && (desiredMax > m_maxY + m_marginTop / m_scaleY
1263 || desiredMin < m_minY - m_marginBottom / m_scaleY) );
1264 }
1265
1269 virtual bool UpdateBBox();
1270
1274 virtual bool SetXView( double pos, double desiredMax, double desiredMin );
1275
1279 virtual bool SetYView( double pos, double desiredMax, double desiredMin );
1280
1281 // wxList m_layers; //!< List of attached plot layers
1282 wxLayerList m_layers; // !< List of attached plot layers
1283 wxMenu m_popmenu; // !< Canvas' context menu
1284 wxColour m_bgColour; // !< Background Colour
1285 wxColour m_fgColour; // !< Foreground Colour
1286 wxColour m_axColour; // !< Axes Colour
1287
1288 double m_minX; // !< Global layer bounding box, left border incl.
1289 double m_maxX; // !< Global layer bounding box, right border incl.
1290 double m_minY; // !< Global layer bounding box, bottom border incl.
1291 double m_maxY; // !< Global layer bounding box, top border incl.
1292 double m_scaleX; // !< Current view's X scale
1293 double m_scaleY; // !< Current view's Y scale
1294 double m_posX; // !< Current view's X position
1295 double m_posY; // !< Current view's Y position
1296 int m_scrX; // !< Current view's X dimension
1297 int m_scrY; // !< Current view's Y dimension
1298 int m_clickedX; // !< Last mouse click X position, for centering and zooming the view
1299 int m_clickedY; // !< Last mouse click Y position, for centering and zooming the view
1300
1302
1306 double m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax;
1307
1308 int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
1309
1310 int m_last_lx, m_last_ly; // !< For double buffering
1311 wxMemoryDC m_buff_dc; // !< For double buffering
1312 wxBitmap* m_buff_bmp; // !< For double buffering
1313 bool m_enableDoubleBuffer; // !< For double buffering
1314 bool m_enableMouseNavigation; // !< For pan/zoom with the mouse.
1315 bool m_enableMouseWheelPan; // !< Trackpad pan/zoom
1317 wxPoint m_mouseMClick; // !< For the middle button "drag" feature
1318 wxPoint m_mouseLClick; // !< Starting coords for rectangular zoom selection
1319 mpInfoLayer* m_movingInfoLayer; // !< For moving info layers over the window area
1322 DECLARE_DYNAMIC_CLASS( mpWindow )
1323 DECLARE_EVENT_TABLE()
1324};
1325
1326// -----------------------------------------------------------------------------
1327// mpFXYVector - provided by Jose Luis Blanco
1328// -----------------------------------------------------------------------------
1329
1350{
1351public:
1355 mpFXYVector( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
1356
1357 virtual ~mpFXYVector() {}
1358
1363 virtual void SetData( const std::vector<double>& xs, const std::vector<double>& ys );
1364
1368 void Clear();
1369
1370protected:
1373 std::vector<double> m_xs, m_ys;
1374
1377 size_t m_index;
1378
1381 double m_minX, m_maxX, m_minY, m_maxY;
1382
1386 void Rewind() override;
1387
1393 bool GetNextXY( double& x, double& y ) override;
1394
1395 size_t GetCount() const override;
1396
1397public:
1400 double GetMinX() const override { return m_minX; }
1401
1404 double GetMinY() const override { return m_minY; }
1405
1408 double GetMaxX() const override { return m_maxX; }
1409
1412 double GetMaxY() const override { return m_maxY; }
1413
1414protected:
1415
1416 DECLARE_DYNAMIC_CLASS( mpFXYVector )
1417};
1418
1419
1420#endif // _MP_MATHPLOT_H_
const char * name
Definition: DXF_plotter.cpp:57
A class providing graphs functionality for a 2D plot (either continuous or a set of points),...
Definition: mathplot.h:1350
double GetMaxY() const override
Returns the actual maximum Y data (loaded in SetData).
Definition: mathplot.h:1412
double GetMinY() const override
Returns the actual minimum Y data (loaded in SetData).
Definition: mathplot.h:1404
double GetMinX() const override
Returns the actual minimum X data (loaded in SetData).
Definition: mathplot.h:1400
std::vector< double > m_xs
The internal copy of the set of data to draw.
Definition: mathplot.h:1373
double m_maxX
Definition: mathplot.h:1381
double GetMaxX() const override
Returns the actual maximum X data (loaded in SetData).
Definition: mathplot.h:1408
virtual ~mpFXYVector()
Definition: mathplot.h:1357
size_t m_index
The internal counter for the "GetNextXY" interface.
Definition: mathplot.h:1377
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,...
Definition: mathplot.h:543
mpScaleBase * m_scaleX
Definition: mathplot.h:586
wxCoord maxDrawX
Definition: mathplot.h:584
virtual void Rewind()=0
Rewind value enumeration with mpFXY::GetNextXY.
virtual size_t GetCount() const =0
int m_flags
Definition: mathplot.h:581
virtual bool GetNextXY(double &x, double &y)=0
Get locus value for next N.
Abstract base class providing plot and labeling functionality for functions F:X->Y.
Definition: mathplot.h:477
virtual double GetY(double x) const =0
Get function value for argument.
int m_flags
Definition: mathplot.h:498
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:509
int m_flags
Definition: mathplot.h:530
virtual double GetX(double y) const =0
Get function value for argument.
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
Definition: mathplot.h:331
virtual bool HasBBox() const override
mpInfoLayer has not bounding box.
Definition: mathplot.h:346
wxPoint m_reference
Definition: mathplot.h:382
wxRect m_dim
Definition: mathplot.h:380
int m_winY
Definition: mathplot.h:385
virtual bool IsInfo() const override
Specifies that this is an Info box layer.
Definition: mathplot.h:357
wxBrush m_brush
Definition: mathplot.h:383
int m_winX
Definition: mathplot.h:384
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Definition: mathplot.h:394
const wxString & GetDisplayName() const
Definition: mathplot.h:242
virtual void Plot(wxDC &dc, mpWindow &w)=0
Plot given view of layer to the given device context.
mpLayerType GetLayerType() const
Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc,...
Definition: mathplot.h:288
wxFont m_font
Definition: mathplot.h:308
void SetFont(const wxFont &font)
Set layer font.
Definition: mathplot.h:279
bool IsVisible() const
Checks whether the layer is visible or not.
Definition: mathplot.h:292
const wxString & GetName() const
Get layer name.
Definition: mathplot.h:240
virtual ~mpLayer()
Definition: mathplot.h:154
virtual double GetMinY() const
Get inclusive bottom border of bounding box.
Definition: mathplot.h:187
bool GetContinuity() const
Gets the 'continuity' property of the layer.
Definition: mathplot.h:265
bool m_continuous
Definition: mathplot.h:313
bool m_showName
Definition: mathplot.h:314
bool m_visible
Definition: mathplot.h:316
virtual bool IsInfo() const
Check whether the layer is an info box.
Definition: mathplot.h:172
void SetContinuity(bool continuity)
Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points...
Definition: mathplot.h:260
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
Definition: mathplot.h:269
virtual void SetName(const wxString &name)
Set layer name.
Definition: mathplot.h:274
const wxFont & GetFont() const
Get font set for this layer.
Definition: mathplot.h:250
const wxPen & GetPen() const
Get pen set for this layer.
Definition: mathplot.h:255
mpLayerType m_type
Definition: mathplot.h:315
void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:296
wxString m_name
Definition: mathplot.h:311
wxBrush m_brush
Definition: mathplot.h:310
wxString m_displayName
Definition: mathplot.h:312
void SetPen(const wxPen &pen)
Set layer pen.
Definition: mathplot.h:284
wxPen m_pen
Definition: mathplot.h:309
void SetBrush(const wxBrush &brush)
Set layer brush.
Definition: mathplot.h:304
virtual double GetMaxX() const
Get inclusive right border of bounding box.
Definition: mathplot.h:182
const wxBrush & GetBrush() const
Get brush set for this layer.
Definition: mathplot.h:300
virtual double GetMinX() const
Get inclusive left border of bounding box.
Definition: mathplot.h:177
virtual double GetMaxY() const
Get inclusive top border of bounding box.
Definition: mathplot.h:192
virtual bool HasBBox() const
Check whether this layer has a bounding box.
Definition: mathplot.h:163
Plot layer implementing a x-scale ruler.
Definition: mathplot.h:613
void SetAxisMinMax(bool lock, double minV, double maxV)
Definition: mathplot.h:682
bool m_axisLocked
Definition: mathplot.h:743
void SetNameAlign(int align)
Definition: mathplot.h:628
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
Definition: mathplot.h:728
double m_offset
Definition: mathplot.h:736
double AbsMaxValue() const
Definition: mathplot.h:672
void GetDataRange(double &minV, double &maxV) const
Definition: mathplot.h:640
std::vector< double > m_tickValues
Definition: mathplot.h:733
bool m_rangeSet
Definition: mathplot.h:742
double AbsVisibleMaxValue() const
Definition: mathplot.h:677
bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:620
void SetAlign(int align)
Set X axis alignment.
Definition: mathplot.h:626
void SetTicks(bool enable)
Set X axis ticks or grid.
Definition: mathplot.h:633
virtual double TransformToPlot(double x) const
Definition: mathplot.h:705
virtual void ResetDataRange()
Definition: mathplot.h:667
virtual void formatLabels()
Definition: mathplot.h:730
int m_maxLabelHeight
Definition: mathplot.h:746
virtual bool IsHorizontal() const =0
double m_axisMin
Definition: mathplot.h:744
double m_maxV
Definition: mathplot.h:741
int m_maxLabelWidth
Definition: mathplot.h:747
bool GetTicks() const
Get X axis ticks or grid.
Definition: mathplot.h:638
virtual void ExtendDataRange(double minV, double maxV)
Definition: mathplot.h:646
std::vector< TICK_LABEL > m_tickLabels
Definition: mathplot.h:734
double m_absVisibleMaxV
Definition: mathplot.h:737
bool m_ticks
Definition: mathplot.h:740
bool GetAxisMinMax(double *minV, double *maxV)
Definition: mathplot.h:689
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV)
Definition: mathplot.h:727
int m_flags
Definition: mathplot.h:738
int m_nameFlags
Definition: mathplot.h:739
virtual ~mpScaleBase()
Definition: mathplot.h:616
virtual double TransformFromPlot(double xplot) const
Definition: mathplot.h:706
double m_axisMax
Definition: mathplot.h:745
virtual ~mpScaleXBase()
Definition: mathplot.h:762
virtual bool IsHorizontal() const override
Definition: mathplot.h:764
Plot layer implementing a y-scale ruler.
Definition: mathplot.h:827
int m_flags
Definition: mathplot.h:861
mpScaleY * m_masterScale
Definition: mathplot.h:860
virtual bool IsHorizontal() const override
Definition: mathplot.h:836
void SetMasterScale(mpScaleY *masterScale)
Definition: mathplot.h:852
bool m_ticks
Definition: mathplot.h:862
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:847
Canvas for plotting mpLayer implementations.
Definition: mathplot.h:907
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1319
bool m_zooming
Definition: mathplot.h:1320
double m_maxY
Definition: mathplot.h:1291
double m_posY
Definition: mathplot.h:1295
int GetMarginLeft() const
Definition: mathplot.h:1185
bool m_enableMouseNavigation
Definition: mathplot.h:1314
int GetYScreen() const
Definition: mathplot.h:1006
void EnableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
Definition: mathplot.h:1070
void SetMarginLeft(int left)
Set the left margin.
Definition: mathplot.h:1176
const wxColour & GetAxesColour()
Get axes draw colour.
Definition: mathplot.h:1221
double m_desiredXmax
Definition: mathplot.h:1306
int m_last_lx
Definition: mathplot.h:1310
bool m_enableMouseWheelPan
Definition: mathplot.h:1315
double m_minY
Definition: mathplot.h:1290
int GetScrX() const
Get current view's X dimension in device context units.
Definition: mathplot.h:996
int GetScrY() const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1005
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1049
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1053
wxMemoryDC m_buff_dc
Definition: mathplot.h:1311
double m_maxX
Definition: mathplot.h:1289
void SetMarginRight(int right)
Set the right margin.
Definition: mathplot.h:1172
int m_marginBottom
Definition: mathplot.h:1308
void LimitView(bool aEnable)
Limit zooming & panning to the area used by the plots.
Definition: mathplot.h:1224
int m_clickedY
Definition: mathplot.h:1299
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1057
wxColour m_bgColour
Definition: mathplot.h:1284
double m_posX
Definition: mathplot.h:1294
wxPoint m_mouseLClick
Definition: mathplot.h:1318
void SetMarginTop(int top)
Set the top margin.
Definition: mathplot.h:1170
void SetPosX(double posX)
Set current view's X position and refresh display.
Definition: mathplot.h:1027
double GetDesiredYmax() const
Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exact...
Definition: mathplot.h:1140
int GetXScreen() const
Definition: mathplot.h:997
int GetMarginTop() const
Definition: mathplot.h:1179
double m_scaleY
Definition: mathplot.h:1293
void SetMarginBottom(int bottom)
Set the bottom margin.
Definition: mathplot.h:1174
void SetPosY(double posY)
Set current view's Y position and refresh display.
Definition: mathplot.h:1032
void SetScaleY(double scaleY)
Set current view's Y scale and refresh display.
Definition: mathplot.h:1016
wxColour m_fgColour
Definition: mathplot.h:1285
bool GetYLocked() const
Definition: mathplot.h:1230
double GetDesiredYmin() const
Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not ex...
Definition: mathplot.h:1134
double m_minX
Definition: mathplot.h:1288
bool CheckYLimits(double &desiredMax, double &desiredMin) const
Definition: mathplot.h:1259
wxRect m_zoomRect
Definition: mathplot.h:1321
wxLayerList m_layers
Definition: mathplot.h:1282
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1061
double GetDesiredXmax() const
Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
Definition: mathplot.h:1128
wxMenu m_popmenu
Definition: mathplot.h:1283
bool m_enableLimitedView
Definition: mathplot.h:1316
int m_clickedX
Definition: mathplot.h:1298
bool CheckXLimits(double &desiredMax, double &desiredMin) const
Definition: mathplot.h:1252
wxBitmap * m_buff_bmp
Definition: mathplot.h:1312
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
Definition: mathplot.h:916
double GetDesiredXmin() const
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
Definition: mathplot.h:1122
wxPoint m_mouseMClick
Definition: mathplot.h:1317
int GetMarginRight() const
Definition: mathplot.h:1181
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
Definition: mathplot.h:1045
int GetMarginBottom() const
Definition: mathplot.h:1183
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
Definition: mathplot.h:1066
wxColour m_axColour
Definition: mathplot.h:1286
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:1159
mpLayer * GetLayerByName(const wxString &name)
Definition: mathplot.h:961
bool m_yLocked
Definition: mathplot.h:1301
double m_scaleX
Definition: mathplot.h:1292
bool m_enableDoubleBuffer
Definition: mathplot.h:1313
void EnableMouseWheelPan(bool enabled)
Enable/disable trackpad friendly panning (2-axis scroll wheel)
Definition: mathplot.h:1074
void LockY(bool aLock)
Definition: mathplot.h:1229
unsigned int CountAllLayers() const
Counts the number of plot layers, whether or not they have a bounding box.
Definition: mathplot.h:1116
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
Definition: mathplot.h:1038
double GetScaleY() const
Get current view's Y scale.
Definition: mathplot.h:976
int m_scrY
Definition: mathplot.h:1297
double GetScaleX() const
Get current view's X scale.
Definition: mathplot.h:970
double GetPosY() const
Get current view's Y position.
Definition: mathplot.h:988
double GetPosX() const
Get current view's X position.
Definition: mathplot.h:982
int m_scrX
Definition: mathplot.h:1296
class WXDLLIMPEXP_MATHPLOT mpPrintout
Definition: mathplot.h:113
__mp_Layer_Type
Definition: mathplot.h:129
@ mpLAYER_INFO
Definition: mathplot.h:133
@ mpLAYER_BITMAP
Definition: mathplot.h:134
@ mpLAYER_UNDEF
Definition: mathplot.h:130
@ mpLAYER_AXIS
Definition: mathplot.h:131
@ mpLAYER_PLOT
Definition: mathplot.h:132
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:428
enum __mp_Layer_Type mpLayerType
std::deque< mpLayer * > wxLayerList
Define the type for the list of layers inside mpWindow.
Definition: mathplot.h:882
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:430
#define mpALIGN_TOP
Aligns label to the top.
Definition: mathplot.h:434
#define WXDLLIMPEXP_MATHPLOT
Definition: mathplot.h:65
@ mpID_FIT
Definition: mathplot.h:118
@ mpID_ZOOM_IN
Definition: mathplot.h:119
@ mpID_CENTER
Definition: mathplot.h:121
@ mpID_ZOOM_OUT
Definition: mathplot.h:120
#define mpX_NORMAL
Set label for X axis in normal mode.
Definition: mathplot.h:444
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:458
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:426
TICK_LABEL(double pos_=0.0, const wxString &label_=wxT(""))
Definition: mathplot.h:710
constexpr int delta