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// Copyright (c) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
11// Licence: wxWindows licence
13
14#ifndef _MP_MATHPLOT_H_
15#define _MP_MATHPLOT_H_
16
55// this definition uses windows dll to export function.
56// WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
57// mathplot_EXPORTS will be defined by cmake
58#ifdef mathplot_EXPORTS
59#define WXDLLIMPEXP_MATHPLOT WXEXPORT
60#define WXDLLIMPEXP_DATA_MATHPLOT( type ) WXEXPORT type
61#else // not making DLL
62#define WXDLLIMPEXP_MATHPLOT
63#define WXDLLIMPEXP_DATA_MATHPLOT( type ) type
64#endif
65
66
67#include <wx/defs.h>
68#include <wx/menu.h>
69#include <wx/scrolwin.h>
70#include <wx/event.h>
71#include <wx/dynarray.h>
72#include <wx/pen.h>
73#include <wx/dcmemory.h>
74#include <wx/string.h>
75#include <wx/print.h>
76#include <wx/image.h>
77
78#include <vector>
79#include <deque>
80#include <stack>
81#include <array>
82#include <algorithm>
83
84// For memory leak debug
85#ifdef _WINDOWS
86#ifdef _DEBUG
87#include <crtdbg.h>
88#define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
89#else
90#define DEBUG_NEW new
91#endif // _DEBUG
92#endif // _WINDOWS
93
94// Separation for axes when set close to border
95#define X_BORDER_SEPARATION 40
96#define Y_BORDER_SEPARATION 60
97
98// -----------------------------------------------------------------------------
99// classes
100// -----------------------------------------------------------------------------
101
111
113enum
114{
115 mpID_FIT = 2000, // !< Fit view to match bounding box of all layers
118 mpID_ZOOM_IN, // !< Zoom into view at clickposition / window center
119 mpID_ZOOM_OUT, // !< Zoom out
120 mpID_CENTER, // !< Center view on click position
121};
122
123// -----------------------------------------------------------------------------
124// mpLayer
125// -----------------------------------------------------------------------------
126
127typedef enum __mp_Layer_Type
128{
129 mpLAYER_UNDEF, // !< Layer type undefined
130 mpLAYER_AXIS, // !< Axis type layer
131 mpLAYER_PLOT, // !< Plot type layer
132 mpLAYER_INFO, // !< Info box type layer
133 mpLAYER_BITMAP // !< Bitmap type layer
135
146class mpScaleBase;
147
148class WXDLLIMPEXP_MATHPLOT mpLayer : public wxObject
149{
150public:
151 mpLayer();
152
153 virtual ~mpLayer() {};
154
162 virtual bool HasBBox() const { return true; }
163
171 virtual bool IsInfo() const { return false; };
172
176 virtual double GetMinX() const { return -1.0; }
177
181 virtual double GetMaxX() const { return 1.0; }
182
186 virtual double GetMinY() const { return -1.0; }
187
191 virtual double GetMaxY() const { return 1.0; }
192
234 virtual void Plot( wxDC& dc, mpWindow& w ) = 0;
235
239 const wxString& GetName() const { return m_name; }
240
241 const wxString& GetDisplayName() const
242 {
243 return m_displayName.IsEmpty() ? m_name : m_displayName;
244 }
245
249 const wxFont& GetFont() const { return m_font; }
250
254 const wxPen& GetPen() const { return m_pen; }
255
259 void SetContinuity( bool continuity ) { m_continuous = continuity; }
260
264 bool GetContinuity() const { return m_continuous; }
265
268 void ShowName( bool show ) { m_showName = show; };
269
273 virtual void SetName( const wxString& name ) { m_name = name; }
274
278 void SetFont( const wxFont& font ) { m_font = font; }
279
283 void SetPen( const wxPen& pen ) { m_pen = pen; }
284
287 mpLayerType GetLayerType() const { return m_type; };
288
291 bool IsVisible() const { return m_visible; };
292
295 void SetVisible( bool show ) { m_visible = show; };
296
299 const wxBrush& GetBrush() const { return m_brush; };
300
303 void SetBrush( const wxBrush& brush ) { m_brush = brush; };
304
305protected:
306
307 wxFont m_font; // !< Layer's font
308 wxPen m_pen; // !< Layer's pen
309 wxBrush m_brush; // !< Layer's brush
310 wxString m_name; // !< Layer's name
312 bool m_continuous; // !< Specify if the layer will be plotted as a continuous line or a set of points.
313 bool m_showName; // !< States whether the name of the layer must be shown (default is true).
314 mpLayerType m_type; // !< Define layer type, which is assigned by constructor
315 bool m_visible; // !< Toggles layer visibility
316
317 DECLARE_DYNAMIC_CLASS( mpLayer )
318};
319
320
321// -----------------------------------------------------------------------------
322// mpInfoLayer
323// -----------------------------------------------------------------------------
324
330{
331public:
333 mpInfoLayer();
334
338 mpInfoLayer( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
339
341 virtual ~mpInfoLayer();
342
345 virtual bool HasBBox() const override { return false; }
346
351 virtual void Plot( wxDC& dc, mpWindow& w ) override;
352
356 virtual bool IsInfo() const override { return true; }
357
361 virtual bool Inside( const wxPoint& point ) const;
362
365 virtual void Move( wxPoint delta );
366
368 virtual void UpdateReference();
369
372 wxPoint GetPosition() const;
373
376 wxSize GetSize() const;
377
378protected:
379 wxRect m_dim; // !< The bounding rectangle of the box. It may be resized dynamically
380 // by the Plot method.
381 wxPoint m_reference; // !< Holds the reference point for movements
382 wxBrush m_brush; // !< The brush to be used for the background
383 int m_winX; // !< Holds the mpWindow size. Used to rescale position when window is
384 int m_winY; // resized.
385
386 DECLARE_DYNAMIC_CLASS( mpInfoLayer )
387};
388
393{
394public:
396 mpInfoLegend();
397
402 mpInfoLegend( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
403
406
411 virtual void Plot( wxDC& dc, mpWindow& w ) override;
412
413protected:
414};
415
416
417// -----------------------------------------------------------------------------
418// mpLayer implementations - functions
419// -----------------------------------------------------------------------------
420
425#define mpALIGNMASK 0x03
427#define mpALIGN_RIGHT 0x00
429#define mpALIGN_CENTER 0x01
431#define mpALIGN_LEFT 0x02
433#define mpALIGN_TOP mpALIGN_RIGHT
435#define mpALIGN_BOTTOM mpALIGN_LEFT
437#define mpALIGN_BORDER_BOTTOM 0x04
439#define mpALIGN_BORDER_TOP 0x05
441#define mpALIGN_FAR_RIGHT 0x06
443#define mpX_NORMAL 0x00
445#define mpX_TIME 0x01
447#define mpX_HOURS 0x02
449#define mpX_DATE 0x03
451#define mpX_DATETIME 0x04
453#define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
455#define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
457#define mpALIGN_NE 0x00
459#define mpALIGN_NW 0x01
461#define mpALIGN_SW 0x02
463#define mpALIGN_SE 0x03
464
476{
477public:
481 mpFX( const wxString& name = wxEmptyString, int flags = mpALIGN_RIGHT );
482
488 virtual double GetY( double x ) const = 0;
489
494 virtual void Plot( wxDC& dc, mpWindow& w ) override;
495
496protected:
497 int m_flags; // !< Holds label alignment
498
499 DECLARE_DYNAMIC_CLASS( mpFX )
500};
501
508{
509public:
513 mpFY( const wxString& name = wxEmptyString, int flags = mpALIGN_TOP );
514
520 virtual double GetX( double y ) const = 0;
521
526 virtual void Plot( wxDC& dc, mpWindow& w ) override;
527
528protected:
529 int m_flags; // !< Holds label alignment
530
531 DECLARE_DYNAMIC_CLASS( mpFY )
532};
533
542{
543public:
547 mpFXY( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
548
552 virtual void Rewind() = 0;
553
559 virtual bool GetNextXY( double& x, double& y ) = 0;
560
561 virtual size_t GetCount() const = 0;
562
567 virtual void Plot( wxDC& dc, mpWindow& w ) override;
568
569 virtual void SetScale( mpScaleBase* scaleX, mpScaleBase* scaleY );
570
571 void UpdateScales();
572
573 double s2x( double plotCoordX ) const;
574 double s2y( double plotCoordY ) const;
575
576 double x2s( double x ) const;
577 double y2s( double y ) const;
578
579protected:
580 int m_flags; // !< Holds label alignment
581
582 // Data to calculate label positioning
583 wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
584 // int drawnPoints;
585 mpScaleBase* m_scaleX, * m_scaleY;
586
591 void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
592
593 DECLARE_DYNAMIC_CLASS( mpFXY )
594};
595
598// -----------------------------------------------------------------------------
599// mpLayer implementations - furniture (scales, ...)
600// -----------------------------------------------------------------------------
601
612{
613public:
614 mpScaleBase();
615 virtual ~mpScaleBase() {};
616
617 virtual bool IsHorizontal() const = 0;
618
619 bool HasBBox() const override { return false; }
620
625 void SetAlign( int align ) { m_flags = align; };
626
627 void SetNameAlign( int align ) { m_nameFlags = align; }
628
632 void SetTicks( bool enable ) { m_ticks = enable; };
633
637 bool GetTicks() const { return m_ticks; };
638
639 void GetDataRange( double& minV, double& maxV ) const
640 {
641 minV = m_minV;
642 maxV = m_maxV;
643 }
644
645 virtual void ExtendDataRange( double minV, double maxV )
646 {
647 if( !m_rangeSet )
648 {
649 m_minV = minV;
650 m_maxV = maxV;
651 m_rangeSet = true;
652 }
653 else
654 {
655 m_minV = std::min( minV, m_minV );
656 m_maxV = std::max( maxV, m_maxV );
657 }
658
659 if( m_minV == m_maxV )
660 {
661 m_minV = m_minV - 1.0;
662 m_maxV = m_maxV + 1.0;
663 }
664 }
665
666 virtual void ResetDataRange()
667 {
668 m_rangeSet = false;
669 }
670
671 double AbsMaxValue() const
672 {
673 return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
674 }
675
676 double AbsVisibleMaxValue() const
677 {
678 return m_absVisibleMaxV;
679 }
680
681 void SetAxisMinMax( bool lock, double minV, double maxV )
682 {
683 m_axisLocked = lock;
684 m_axisMin = minV;
685 m_axisMax = maxV;
686 }
687
688 bool GetAxisMinMax( double* minV, double* maxV )
689 {
690 if( m_axisLocked )
691 {
692 *minV = m_axisMin;
693 *maxV = m_axisMax;
694 }
695 else if( !m_tickValues.empty() )
696 {
697 *minV = m_tickValues.front();
698 *maxV = m_tickValues.back();
699 }
700
701 return m_axisLocked;
702 }
703
704 virtual double TransformToPlot( double x ) const { return 0.0; };
705 virtual double TransformFromPlot( double xplot ) const { return 0.0; };
706
708 {
709 TICK_LABEL( double pos_ = 0.0, const wxString& label_ = wxT( "" ) ) :
710 pos( pos_ ),
711 label( label_ ),
712 visible( true )
713 {}
714
715 double pos;
716 wxString label;
718 };
719
720protected:
721
722 void updateTickLabels( wxDC& dc, mpWindow& w );
723 void computeLabelExtents( wxDC& dc, mpWindow& w );
724
725 // virtual int getLabelDecimalDigits(int maxDigits) const;
726 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) {};
727 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) {};
728
729 virtual void formatLabels() {};
730
731protected:
732 std::vector<double> m_tickValues;
733 std::vector<TICK_LABEL> m_tickLabels;
734
735 double m_offset, m_scale;
737 int m_flags; // !< Flag for axis alignment
739 bool m_ticks; // !< Flag to toggle between ticks or grid
740 double m_minV, m_maxV;
743 double m_axisMin;
744 double m_axisMax;
747};
748
750{
751public:
759 mpScaleXBase( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true,
760 unsigned int type = mpX_NORMAL );
761 virtual ~mpScaleXBase() {};
762
763 virtual bool IsHorizontal() const override { return true; }
764 virtual void Plot( wxDC& dc, mpWindow& w ) override;
765
766 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
767
768 DECLARE_DYNAMIC_CLASS( mpScaleXBase )
769};
770
771
773{
774public:
782 mpScaleX( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true,
783 unsigned int type = mpX_NORMAL );
784
785 virtual double TransformToPlot( double x ) const override;
786 virtual double TransformFromPlot( double xplot ) const override;
787
788protected:
789 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
790
791 DECLARE_DYNAMIC_CLASS( mpScaleX )
792};
793
794
796{
797public:
805 mpScaleXLog( const wxString& name = wxT( "log(X)" ), int flags = mpALIGN_CENTER,
806 bool ticks = true, unsigned int type = mpX_NORMAL );
807
808 virtual double TransformToPlot( double x ) const override;
809 virtual double TransformFromPlot( double xplot ) const override;
810
811protected:
812 void recalculateTicks( wxDC& dc, mpWindow& w ) override;
813
814 DECLARE_DYNAMIC_CLASS( mpScaleXLog )
815};
816
817
826{
827public:
833 mpScaleY( const wxString& name = wxT( "Y" ), int flags = mpALIGN_CENTER, bool ticks = true );
834
835 virtual bool IsHorizontal() const override { return false; }
836
840 virtual void Plot( wxDC& dc, mpWindow& w ) override;
841
846 virtual bool HasBBox() const override { return false; }
847
848 virtual double TransformToPlot( double x ) const override;
849 virtual double TransformFromPlot( double xplot ) const override;
850
851 void SetMasterScale( mpScaleY* masterScale ) { m_masterScale = masterScale; }
852
853protected:
854 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
855 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
856
857 void computeSlaveTicks( mpWindow& w );
858
860 int m_flags; // !< Flag for axis alignment
861 bool m_ticks; // !< Flag to toggle between ticks or grid
862
863 DECLARE_DYNAMIC_CLASS( mpScaleY )
864};
865
866// -----------------------------------------------------------------------------
867// mpWindow
868// -----------------------------------------------------------------------------
869
874#define mpMOUSEMODE_DRAG 0
876#define mpMOUSEMODE_ZOOMBOX 1
877
880// WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, wxLayerList );
881typedef std::deque<mpLayer*> wxLayerList;
882
905class WXDLLIMPEXP_MATHPLOT mpWindow : public wxWindow
906{
907public:
912 {
913 NONE,
917 ZOOM,
920 COUNT // Internal use only
921 };
922
927 {
928 /* If this bundled wxMathPlot implementation is to remain single-header and not dependent
929 * on any part of KiCad, then the SIM_MOUSE_WHEEL_ACTION_SET struct must be duplicated
930 * here. SIM_PLOT_TAB::convertMouseWheelActions is used to convert from
931 * SIM_MOUSE_WHEEL_ACTION_SET to mpWindow::MouseWheelActionSet. */
932
938 };
939
940 mpWindow();
941 mpWindow( wxWindow* parent, wxWindowID id );
942 ~mpWindow();
943
947 wxMenu* GetPopupMenu() { return &m_popmenu; }
948
957 bool AddLayer( mpLayer* layer, bool refreshDisplay = true );
958
969 bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true );
970
977 void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true );
978
979
985 mpLayer* GetLayer( int position ) const;
986
991 const mpLayer* GetLayerByName( const wxString& name ) const;
992 mpLayer* GetLayerByName( const wxString& name )
993 {
994 return const_cast<mpLayer*>( static_cast<const mpWindow*>( this )->GetLayerByName( name ) );
995 }
996
1001 double GetScaleX() const { return m_scaleX; };
1002
1007 double GetScaleY() const { return m_scaleY; }
1008
1013 double GetPosX() const { return m_posX; }
1014
1019 double GetPosY() const { return m_posY; }
1020
1027 int GetScrX() const { return m_scrX; }
1028 int GetXScreen() const { return m_scrX; }
1029
1036 int GetScrY() const { return m_scrY; }
1037 int GetYScreen() const { return m_scrY; }
1038
1042 void SetScaleX( double scaleX );
1043
1047 void SetScaleY( double scaleY )
1048 {
1049 if( scaleY != 0 )
1050 m_scaleY = scaleY;
1051
1052 UpdateAll();
1053 }
1054
1058 void SetPosX( double posX ) { m_posX = posX; UpdateAll(); }
1059
1063 void SetPosY( double posY ) { m_posY = posY; UpdateAll(); }
1064
1069 void SetPos( double posX, double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
1070
1076 void SetScr( int scrX, int scrY ) { m_scrX = scrX; m_scrY = scrY; }
1077
1080 inline double p2x( wxCoord pixelCoordX ) { return m_posX + pixelCoordX / m_scaleX; }
1081
1084 inline double p2y( wxCoord pixelCoordY ) { return m_posY - pixelCoordY / m_scaleY; }
1085
1088 inline wxCoord x2p( double x ) { return (wxCoord) ( (x - m_posX) * m_scaleX ); }
1089
1092 inline wxCoord y2p( double y ) { return (wxCoord) ( (m_posY - y) * m_scaleY ); }
1093
1094
1097 void EnableDoubleBuffer( bool enabled ) { m_enableDoubleBuffer = enabled; }
1098
1101 void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
1102
1104 void SetMouseWheelActions( const MouseWheelActionSet& s ) { m_mouseWheelActions = s; }
1105
1110 void Fit() override;
1111
1118 void Fit( double xMin, double xMax, double yMin, double yMax,
1119 const wxCoord* printSizeX = nullptr, const wxCoord* printSizeY = nullptr,
1120 wxOrientation directions = wxBOTH );
1121
1126 void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
1127 void ZoomIn( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions = wxBOTH );
1128
1133 void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
1134 void ZoomOut( const wxPoint& centerPoint, double zoomFactor,
1135 wxOrientation directions = wxBOTH );
1136
1139 void ZoomRect( wxPoint p0, wxPoint p1 );
1140
1142 void UpdateAll();
1143
1144 // Added methods by Davide Rondini
1145
1148 unsigned int CountAllLayers() const { return m_layers.size(); };
1149
1154 double GetDesiredXmin() const { return m_desiredXmin; }
1155
1160 double GetDesiredXmax() const { return m_desiredXmax; }
1161
1166 double GetDesiredYmin() const { return m_desiredYmin; }
1167
1172 double GetDesiredYmax() const { return m_desiredYmax; }
1173
1177 void GetBoundingBox( double* bbox ) const;
1178
1184 bool SaveScreenshot( const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_BMP,
1185 wxSize imageSize = wxDefaultSize, bool fit = false );
1186
1192
1199 void SetMargins( int top, int right, int bottom, int left );
1200
1202 void SetMarginTop( int top ) { m_marginTop = top; };
1204 void SetMarginRight( int right ) { m_marginRight = right; };
1206 void SetMarginBottom( int bottom ) { m_marginBottom = bottom; };
1208 void SetMarginLeft( int left ) { m_marginLeft = left; };
1209
1211 int GetMarginTop() const { return m_marginTop; };
1213 int GetMarginRight() const { return m_marginRight; };
1215 int GetMarginBottom() const { return m_marginBottom; };
1217 int GetMarginLeft() const { return m_marginLeft; };
1218
1222 mpInfoLayer* IsInsideInfoLayer( wxPoint& point );
1223
1227 void SetLayerVisible( const wxString& name, bool viewable );
1228
1232 bool IsLayerVisible( const wxString& name ) const;
1233
1237 void SetLayerVisible( const unsigned int position, bool viewable );
1238
1242 bool IsLayerVisible( unsigned int position ) const;
1243
1248 void SetColourTheme( const wxColour& bgColour, const wxColour& drawColour,
1249 const wxColour& axesColour );
1250
1253 const wxColour& GetAxesColour() { return m_axColour; };
1254
1256 void LimitView( bool aEnable )
1257 {
1258 m_enableLimitedView = aEnable;
1259 }
1260
1261 void LockY( bool aLock ) { m_yLocked = aLock; }
1262 bool GetYLocked() const { return m_yLocked; }
1263
1264 void ZoomUndo();
1265 void ZoomRedo();
1266 int UndoZoomStackSize() const { return m_undoZoomStack.size(); }
1267 int RedoZoomStackSize() const { return m_redoZoomStack.size(); }
1268
1270 void AdjustLimitedView( wxOrientation directions = wxBOTH );
1271
1272 void OnFit( wxCommandEvent& event );
1273 void OnCenter( wxCommandEvent& event );
1274
1275protected:
1276 static MouseWheelActionSet defaultMouseWheelActions();
1277
1278 void pushZoomUndo( const std::array<double, 4>& aZoom );
1279
1280 void OnPaint( wxPaintEvent& event ); // !< Paint handler, will plot all attached layers
1281 void OnSize( wxSizeEvent& event ); // !< Size handler, will update scroll bar sizes
1282
1283 void OnShowPopupMenu( wxMouseEvent& event ); // !< Mouse handler, will show context menu
1284 void OnMouseMiddleDown( wxMouseEvent& event ); // !< Mouse handler, for detecting when the user
1285
1286 // !< drags with the middle button or just "clicks" for the menu
1287 void onZoomIn( wxCommandEvent& event ); // !< Context menu handler
1288 void onZoomOut( wxCommandEvent& event ); // !< Context menu handler
1289 void onZoomUndo( wxCommandEvent& event ); // !< Context menu handler
1290 void onZoomRedo( wxCommandEvent& event ); // !< Context menu handler
1291 void onMouseWheel( wxMouseEvent& event ); // !< Mouse handler for the wheel
1292 void onMagnify( wxMouseEvent& event ); // !< Pinch zoom handler
1293 void onMouseMove( wxMouseEvent& event ); // !< Mouse handler for mouse motion (for pan)
1294 void onMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
1295 void onMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
1296
1297 void DoZoom( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions );
1298 void RecomputeDesiredX( double& min, double& max );
1299 void RecomputeDesiredY( double& min, double& max );
1300 wxOrientation ViewNeedsRefitting( wxOrientation directions ) const;
1301
1302 void PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction action );
1303
1307 virtual bool UpdateBBox();
1308
1312 virtual bool SetXView( double pos, double desiredMax, double desiredMin );
1313
1317 virtual bool SetYView( double pos, double desiredMax, double desiredMin );
1318
1319 // wxList m_layers; //!< List of attached plot layers
1320 wxLayerList m_layers; // !< List of attached plot layers
1321 wxMenu m_popmenu; // !< Canvas' context menu
1322 wxColour m_bgColour; // !< Background Colour
1323 wxColour m_fgColour; // !< Foreground Colour
1324 wxColour m_axColour; // !< Axes Colour
1325
1326 double m_minX; // !< Global layer bounding box, left border incl.
1327 double m_maxX; // !< Global layer bounding box, right border incl.
1328 double m_minY; // !< Global layer bounding box, bottom border incl.
1329 double m_maxY; // !< Global layer bounding box, top border incl.
1330 double m_scaleX; // !< Current view's X scale
1331 double m_scaleY; // !< Current view's Y scale
1332 double m_posX; // !< Current view's X position
1333 double m_posY; // !< Current view's Y position
1334 int m_scrX; // !< Current view's X dimension
1335 int m_scrY; // !< Current view's Y dimension
1336 int m_clickedX; // !< Last mouse click X position, for centering and zooming the view
1337 int m_clickedY; // !< Last mouse click Y position, for centering and zooming the view
1338
1340
1347 double m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax;
1348
1349 // These are gaps between the curve extrema and the edges of the plot area, expressed as
1350 // a factor of global layer bounding box width/height.
1353
1354 int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
1355
1356 int m_last_lx, m_last_ly; // !< For double buffering
1357 wxMemoryDC m_buff_dc; // !< For double buffering
1358 wxBitmap* m_buff_bmp; // !< For double buffering
1359 bool m_enableDoubleBuffer; // !< For double buffering
1360 bool m_enableMouseNavigation; // !< For pan/zoom with the mouse.
1363 wxPoint m_mouseMClick; // !< For the middle button "drag" feature
1364 wxPoint m_mouseLClick; // !< Starting coords for rectangular zoom selection
1365 mpInfoLayer* m_movingInfoLayer; // !< For moving info layers over the window area
1368 std::stack<std::array<double, 4>> m_undoZoomStack;
1369 std::stack<std::array<double, 4>> m_redoZoomStack;
1370
1371 DECLARE_DYNAMIC_CLASS( mpWindow )
1372 DECLARE_EVENT_TABLE()
1373
1374private:
1376
1377 template <typename... Ts>
1378 mpWindow( DelegatingContructorTag, Ts&&... windowArgs );
1379
1380 void initializeGraphicsContext();
1381};
1382
1383// -----------------------------------------------------------------------------
1384// mpFXYVector - provided by Jose Luis Blanco
1385// -----------------------------------------------------------------------------
1386
1407{
1408public:
1412 mpFXYVector( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
1413
1414 virtual ~mpFXYVector() {}
1415
1420 virtual void SetData( const std::vector<double>& xs, const std::vector<double>& ys );
1421
1425 void Clear();
1426
1427protected:
1430 std::vector<double> m_xs, m_ys;
1431
1434 size_t m_index;
1435
1438 double m_minX, m_maxX, m_minY, m_maxY;
1439
1443 void Rewind() override;
1444
1450 bool GetNextXY( double& x, double& y ) override;
1451
1452 size_t GetCount() const override;
1453
1454public:
1457 double GetMinX() const override { return m_minX; }
1458
1461 double GetMinY() const override { return m_minY; }
1462
1465 double GetMaxX() const override { return m_maxX; }
1466
1469 double GetMaxY() const override { return m_maxY; }
1470
1471protected:
1472
1473 DECLARE_DYNAMIC_CLASS( mpFXYVector )
1474};
1475
1476
1477#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:1407
double GetMaxY() const override
Returns the actual maximum Y data (loaded in SetData).
Definition: mathplot.h:1469
double GetMinY() const override
Returns the actual minimum Y data (loaded in SetData).
Definition: mathplot.h:1461
double GetMinX() const override
Returns the actual minimum X data (loaded in SetData).
Definition: mathplot.h:1457
std::vector< double > m_xs
The internal copy of the set of data to draw.
Definition: mathplot.h:1430
double m_maxX
Definition: mathplot.h:1438
double GetMaxX() const override
Returns the actual maximum X data (loaded in SetData).
Definition: mathplot.h:1465
virtual ~mpFXYVector()
Definition: mathplot.h:1414
size_t m_index
The internal counter for the "GetNextXY" interface.
Definition: mathplot.h:1434
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,...
Definition: mathplot.h:542
mpScaleBase * m_scaleX
Definition: mathplot.h:585
wxCoord maxDrawX
Definition: mathplot.h:583
virtual void Rewind()=0
Rewind value enumeration with mpFXY::GetNextXY.
virtual size_t GetCount() const =0
int m_flags
Definition: mathplot.h:580
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:476
virtual double GetY(double x) const =0
Get function value for argument.
int m_flags
Definition: mathplot.h:497
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:508
int m_flags
Definition: mathplot.h:529
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:330
virtual bool HasBBox() const override
mpInfoLayer has not bounding box.
Definition: mathplot.h:345
wxPoint m_reference
Definition: mathplot.h:381
wxRect m_dim
Definition: mathplot.h:379
int m_winY
Definition: mathplot.h:384
virtual bool IsInfo() const override
Specifies that this is an Info box layer.
Definition: mathplot.h:356
wxBrush m_brush
Definition: mathplot.h:382
int m_winX
Definition: mathplot.h:383
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Definition: mathplot.h:393
const wxString & GetDisplayName() const
Definition: mathplot.h:241
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:287
wxFont m_font
Definition: mathplot.h:307
void SetFont(const wxFont &font)
Set layer font.
Definition: mathplot.h:278
bool IsVisible() const
Checks whether the layer is visible or not.
Definition: mathplot.h:291
const wxString & GetName() const
Get layer name.
Definition: mathplot.h:239
virtual ~mpLayer()
Definition: mathplot.h:153
virtual double GetMinY() const
Get inclusive bottom border of bounding box.
Definition: mathplot.h:186
bool GetContinuity() const
Gets the 'continuity' property of the layer.
Definition: mathplot.h:264
bool m_continuous
Definition: mathplot.h:312
bool m_showName
Definition: mathplot.h:313
bool m_visible
Definition: mathplot.h:315
virtual bool IsInfo() const
Check whether the layer is an info box.
Definition: mathplot.h:171
void SetContinuity(bool continuity)
Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points...
Definition: mathplot.h:259
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
Definition: mathplot.h:268
virtual void SetName(const wxString &name)
Set layer name.
Definition: mathplot.h:273
const wxFont & GetFont() const
Get font set for this layer.
Definition: mathplot.h:249
const wxPen & GetPen() const
Get pen set for this layer.
Definition: mathplot.h:254
mpLayerType m_type
Definition: mathplot.h:314
void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:295
wxString m_name
Definition: mathplot.h:310
wxBrush m_brush
Definition: mathplot.h:309
wxString m_displayName
Definition: mathplot.h:311
void SetPen(const wxPen &pen)
Set layer pen.
Definition: mathplot.h:283
wxPen m_pen
Definition: mathplot.h:308
void SetBrush(const wxBrush &brush)
Set layer brush.
Definition: mathplot.h:303
virtual double GetMaxX() const
Get inclusive right border of bounding box.
Definition: mathplot.h:181
const wxBrush & GetBrush() const
Get brush set for this layer.
Definition: mathplot.h:299
virtual double GetMinX() const
Get inclusive left border of bounding box.
Definition: mathplot.h:176
virtual double GetMaxY() const
Get inclusive top border of bounding box.
Definition: mathplot.h:191
virtual bool HasBBox() const
Check whether this layer has a bounding box.
Definition: mathplot.h:162
Plot layer implementing a x-scale ruler.
Definition: mathplot.h:612
void SetAxisMinMax(bool lock, double minV, double maxV)
Definition: mathplot.h:681
bool m_axisLocked
Definition: mathplot.h:742
void SetNameAlign(int align)
Definition: mathplot.h:627
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
Definition: mathplot.h:727
double m_offset
Definition: mathplot.h:735
double AbsMaxValue() const
Definition: mathplot.h:671
void GetDataRange(double &minV, double &maxV) const
Definition: mathplot.h:639
std::vector< double > m_tickValues
Definition: mathplot.h:732
bool m_rangeSet
Definition: mathplot.h:741
double AbsVisibleMaxValue() const
Definition: mathplot.h:676
bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:619
void SetAlign(int align)
Set X axis alignment.
Definition: mathplot.h:625
void SetTicks(bool enable)
Set X axis ticks or grid.
Definition: mathplot.h:632
virtual double TransformToPlot(double x) const
Definition: mathplot.h:704
virtual void ResetDataRange()
Definition: mathplot.h:666
virtual void formatLabels()
Definition: mathplot.h:729
int m_maxLabelHeight
Definition: mathplot.h:745
virtual bool IsHorizontal() const =0
double m_axisMin
Definition: mathplot.h:743
double m_maxV
Definition: mathplot.h:740
int m_maxLabelWidth
Definition: mathplot.h:746
bool GetTicks() const
Get X axis ticks or grid.
Definition: mathplot.h:637
virtual void ExtendDataRange(double minV, double maxV)
Definition: mathplot.h:645
std::vector< TICK_LABEL > m_tickLabels
Definition: mathplot.h:733
double m_absVisibleMaxV
Definition: mathplot.h:736
bool m_ticks
Definition: mathplot.h:739
bool GetAxisMinMax(double *minV, double *maxV)
Definition: mathplot.h:688
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV)
Definition: mathplot.h:726
int m_flags
Definition: mathplot.h:737
int m_nameFlags
Definition: mathplot.h:738
virtual ~mpScaleBase()
Definition: mathplot.h:615
virtual double TransformFromPlot(double xplot) const
Definition: mathplot.h:705
double m_axisMax
Definition: mathplot.h:744
virtual ~mpScaleXBase()
Definition: mathplot.h:761
virtual bool IsHorizontal() const override
Definition: mathplot.h:763
Plot layer implementing a y-scale ruler.
Definition: mathplot.h:826
int m_flags
Definition: mathplot.h:860
mpScaleY * m_masterScale
Definition: mathplot.h:859
virtual bool IsHorizontal() const override
Definition: mathplot.h:835
void SetMasterScale(mpScaleY *masterScale)
Definition: mathplot.h:851
bool m_ticks
Definition: mathplot.h:861
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:846
Canvas for plotting mpLayer implementations.
Definition: mathplot.h:906
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1365
bool m_zooming
Definition: mathplot.h:1366
int RedoZoomStackSize() const
Definition: mathplot.h:1267
double m_maxY
Definition: mathplot.h:1329
double m_posY
Definition: mathplot.h:1333
int GetMarginLeft() const
Definition: mathplot.h:1217
bool m_enableMouseNavigation
Definition: mathplot.h:1360
int GetYScreen() const
Definition: mathplot.h:1037
void EnableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
Definition: mathplot.h:1101
void SetMarginLeft(int left)
Set the left margin.
Definition: mathplot.h:1208
const wxColour & GetAxesColour()
Get axes draw colour.
Definition: mathplot.h:1253
double m_desiredXmax
Definition: mathplot.h:1347
int m_last_lx
Definition: mathplot.h:1356
MouseWheelActionSet m_mouseWheelActions
Definition: mathplot.h:1362
double m_minY
Definition: mathplot.h:1328
int GetScrX() const
Get current view's X dimension in device context units.
Definition: mathplot.h:1027
int GetScrY() const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1036
void SetMouseWheelActions(const MouseWheelActionSet &s)
Set the pan/zoom actions corresponding to mousewheel/trackpad events.
Definition: mathplot.h:1104
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1080
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1084
wxMemoryDC m_buff_dc
Definition: mathplot.h:1357
double m_maxX
Definition: mathplot.h:1327
void SetMarginRight(int right)
Set the right margin.
Definition: mathplot.h:1204
int m_marginBottom
Definition: mathplot.h:1354
void LimitView(bool aEnable)
Enable limiting of zooming & panning to the area used by the plots.
Definition: mathplot.h:1256
int m_clickedY
Definition: mathplot.h:1337
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1088
wxColour m_bgColour
Definition: mathplot.h:1322
MouseWheelAction
Enumerates the possible mouse wheel actions that can be performed on the plot.
Definition: mathplot.h:912
double m_leftRightPlotGapFactor
Definition: mathplot.h:1352
double m_posX
Definition: mathplot.h:1332
wxPoint m_mouseLClick
Definition: mathplot.h:1364
void SetMarginTop(int top)
Set the top margin.
Definition: mathplot.h:1202
std::stack< std::array< double, 4 > > m_redoZoomStack
Definition: mathplot.h:1369
void SetPosX(double posX)
Set current view's X position and refresh display.
Definition: mathplot.h:1058
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:1172
int GetXScreen() const
Definition: mathplot.h:1028
int GetMarginTop() const
Definition: mathplot.h:1211
double m_scaleY
Definition: mathplot.h:1331
void SetMarginBottom(int bottom)
Set the bottom margin.
Definition: mathplot.h:1206
void SetPosY(double posY)
Set current view's Y position and refresh display.
Definition: mathplot.h:1063
void SetScaleY(double scaleY)
Set current view's Y scale and refresh display.
Definition: mathplot.h:1047
wxColour m_fgColour
Definition: mathplot.h:1323
bool GetYLocked() const
Definition: mathplot.h:1262
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:1166
double m_minX
Definition: mathplot.h:1326
wxRect m_zoomRect
Definition: mathplot.h:1367
wxLayerList m_layers
Definition: mathplot.h:1320
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1092
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:1160
wxMenu m_popmenu
Definition: mathplot.h:1321
bool m_enableLimitedView
Definition: mathplot.h:1361
int m_clickedX
Definition: mathplot.h:1336
wxBitmap * m_buff_bmp
Definition: mathplot.h:1358
double m_topBottomPlotGapFactor
Definition: mathplot.h:1351
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
Definition: mathplot.h:947
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:1154
wxPoint m_mouseMClick
Definition: mathplot.h:1363
std::stack< std::array< double, 4 > > m_undoZoomStack
Definition: mathplot.h:1368
int GetMarginRight() const
Definition: mathplot.h:1213
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
Definition: mathplot.h:1076
int GetMarginBottom() const
Definition: mathplot.h:1215
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
Definition: mathplot.h:1097
wxColour m_axColour
Definition: mathplot.h:1324
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:1191
mpLayer * GetLayerByName(const wxString &name)
Definition: mathplot.h:992
bool m_yLocked
Definition: mathplot.h:1339
int UndoZoomStackSize() const
Definition: mathplot.h:1266
double m_scaleX
Definition: mathplot.h:1330
bool m_enableDoubleBuffer
Definition: mathplot.h:1359
void LockY(bool aLock)
Definition: mathplot.h:1261
unsigned int CountAllLayers() const
Counts the number of plot layers, whether or not they have a bounding box.
Definition: mathplot.h:1148
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
Definition: mathplot.h:1069
double GetScaleY() const
Get current view's Y scale.
Definition: mathplot.h:1007
int m_scrY
Definition: mathplot.h:1335
double GetScaleX() const
Get current view's X scale.
Definition: mathplot.h:1001
double GetPosY() const
Get current view's Y position.
Definition: mathplot.h:1019
double GetPosX() const
Get current view's X position.
Definition: mathplot.h:1013
int m_scrX
Definition: mathplot.h:1334
@ NONE
Definition: kibis.h:54
class WXDLLIMPEXP_MATHPLOT mpPrintout
Definition: mathplot.h:110
__mp_Layer_Type
Definition: mathplot.h:128
@ mpLAYER_INFO
Definition: mathplot.h:132
@ mpLAYER_BITMAP
Definition: mathplot.h:133
@ mpLAYER_UNDEF
Definition: mathplot.h:129
@ mpLAYER_AXIS
Definition: mathplot.h:130
@ mpLAYER_PLOT
Definition: mathplot.h:131
@ mpID_ZOOM_REDO
Definition: mathplot.h:117
@ mpID_FIT
Definition: mathplot.h:115
@ mpID_ZOOM_IN
Definition: mathplot.h:118
@ mpID_CENTER
Definition: mathplot.h:120
@ mpID_ZOOM_UNDO
Definition: mathplot.h:116
@ mpID_ZOOM_OUT
Definition: mathplot.h:119
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:427
enum __mp_Layer_Type mpLayerType
std::deque< mpLayer * > wxLayerList
Define the type for the list of layers inside mpWindow.
Definition: mathplot.h:881
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:429
#define mpALIGN_TOP
Aligns label to the top.
Definition: mathplot.h:433
#define WXDLLIMPEXP_MATHPLOT
wxMathPlot is a framework for mathematical graph plotting in wxWindows.
Definition: mathplot.h:62
#define mpX_NORMAL
Set label for X axis in normal mode.
Definition: mathplot.h:443
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:457
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
TICK_LABEL(double pos_=0.0, const wxString &label_=wxT(""))
Definition: mathplot.h:709
Contains the set of modified mouse wheel actions that can be performed on the plot.
Definition: mathplot.h:927
MouseWheelAction horizontal
Definition: mathplot.h:937
MouseWheelAction verticalWithShift
Definition: mathplot.h:935
MouseWheelAction verticalWithCtrl
Definition: mathplot.h:934
MouseWheelAction verticalWithAlt
Definition: mathplot.h:936
MouseWheelAction verticalUnmodified
Definition: mathplot.h:933
constexpr int delta