KiCad PCB EDA Suite
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
54// this definition uses windows dll to export function.
55// WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
56// mathplot_EXPORTS will be defined by cmake
57#ifdef mathplot_EXPORTS
58#define WXDLLIMPEXP_MATHPLOT WXEXPORT
59#define WXDLLIMPEXP_DATA_MATHPLOT( type ) WXEXPORT type
60#else // not making DLL
61#define WXDLLIMPEXP_MATHPLOT
62#define WXDLLIMPEXP_DATA_MATHPLOT( type ) type
63#endif
64
65#include <vector>
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
79#include <deque>
80
81#include <algorithm>
82
83// For memory leak debug
84#ifdef _WINDOWS
85#ifdef _DEBUG
86#include <crtdbg.h>
87#define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
88#else
89#define DEBUG_NEW new
90#endif // _DEBUG
91#endif // _WINDOWS
92
93// Separation for axes when set close to border
94#define X_BORDER_SEPARATION 40
95#define Y_BORDER_SEPARATION 60
96
97// -----------------------------------------------------------------------------
98// classes
99// -----------------------------------------------------------------------------
100
111
113enum
114{
115 mpID_FIT = 2000, // !< Fit view to match bounding box of all layers
116 mpID_ZOOM_IN, // !< Zoom into view at clickposition / window center
117 mpID_ZOOM_OUT, // !< Zoom out
118 mpID_CENTER, // !< Center view on click position
119 mpID_LOCKASPECT, // !< Lock x/y scaling aspect
120};
121
122// -----------------------------------------------------------------------------
123// mpLayer
124// -----------------------------------------------------------------------------
125
126typedef enum __mp_Layer_Type
127{
128 mpLAYER_UNDEF, // !< Layer type undefined
129 mpLAYER_AXIS, // !< Axis type layer
130 mpLAYER_PLOT, // !< Plot type layer
131 mpLAYER_INFO, // !< Info box type layer
132 mpLAYER_BITMAP // !< Bitmap type layer
134
145class mpScaleBase;
146
147class WXDLLIMPEXP_MATHPLOT mpLayer : public wxObject
148{
149public:
150 mpLayer();
151
152 virtual ~mpLayer() {};
153
161 virtual bool HasBBox() const { return true; }
162
170 virtual bool IsInfo() const { return false; };
171
175 virtual double GetMinX() const { return -1.0; }
176
180 virtual double GetMaxX() const { return 1.0; }
181
185 virtual double GetMinY() const { return -1.0; }
186
190 virtual double GetMaxY() const { return 1.0; }
191
233 virtual void Plot( wxDC& dc, mpWindow& w ) = 0;
234
238 const wxString& GetName() const { return m_name; }
239
243 const wxFont& GetFont() const { return m_font; }
244
248 const wxPen& GetPen() const { return m_pen; }
249
253 void SetContinuity( bool continuity ) { m_continuous = continuity; }
254
258 bool GetContinuity() const { return m_continuous; }
259
262 void ShowName( bool show ) { m_showName = show; };
263
267 virtual void SetName( wxString name ) { m_name = name; }
268
272 void SetFont( wxFont& font ) { m_font = font; }
273
277 void SetPen( wxPen pen ) { m_pen = pen; }
278
281 void SetDrawOutsideMargins( bool drawModeOutside ) { m_drawOutsideMargins = drawModeOutside; };
282
285 bool GetDrawOutsideMargins() { return m_drawOutsideMargins; };
286
290 wxBitmap GetColourSquare( int side = 16 ) const;
291
294 mpLayerType GetLayerType() const { return m_type; };
295
298 bool IsVisible() const { return m_visible; };
299
302 void SetVisible( bool show ) { m_visible = show; };
303
306 const wxBrush& GetBrush() const { return m_brush; };
307
310 void SetBrush( wxBrush brush ) { m_brush = brush; };
311
312protected:
313
314 wxFont m_font; // !< Layer's font
315 wxPen m_pen; // !< Layer's pen
316 wxBrush m_brush; // !< Layer's brush
317 wxString m_name; // !< Layer's name
318 bool m_continuous; // !< Specify if the layer will be plotted as a continuous line or a set of points.
319 bool m_showName; // !< States whether the name of the layer must be shown (default is true).
320 bool m_drawOutsideMargins; // !< select if the layer should draw only inside margins or over all DC
321 mpLayerType m_type; // !< Define layer type, which is assigned by constructor
322 bool m_visible; // !< Toggles layer visibility
323 DECLARE_DYNAMIC_CLASS( mpLayer )
324};
325
326
327// -----------------------------------------------------------------------------
328// mpInfoLayer
329// -----------------------------------------------------------------------------
330
336{
337public:
339 mpInfoLayer();
340
344 mpInfoLayer( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
345
347 virtual ~mpInfoLayer();
348
353 virtual void UpdateInfo( mpWindow& w, wxEvent& event );
354
357 virtual bool HasBBox() const override { return false; }
358
363 virtual void Plot( wxDC& dc, mpWindow& w ) override;
364
368 virtual bool IsInfo() const override { return true; }
369
373 virtual bool Inside( const wxPoint& point ) const;
374
377 virtual void Move( wxPoint delta );
378
380 virtual void UpdateReference();
381
384 wxPoint GetPosition() const;
385
388 wxSize GetSize() const;
389
392 const wxRect& GetRectangle() const { return m_dim; };
393
394protected:
395 wxRect m_dim; // !< The bounding rectangle of the box. It may be resized dynamically by the Plot method.
396 wxPoint m_reference; // !< Holds the reference point for movements
397 wxBrush m_brush; // !< The brush to be used for the background
398 int m_winX, m_winY; // !< Holds the mpWindow size. Used to rescale position when window is resized.
399
400 DECLARE_DYNAMIC_CLASS( mpInfoLayer )
401};
402
407{
408public:
410 mpInfoCoords();
414 mpInfoCoords( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
415
418
422 virtual void UpdateInfo( mpWindow& w, wxEvent& event ) override;
423
428 virtual void Plot( wxDC& dc, mpWindow& w ) override;
429
430protected:
431 wxString m_content; // !< string holding the coordinates to be drawn.
432};
433
438{
439public:
441 mpInfoLegend();
442
447 mpInfoLegend( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
448
451
455 virtual void UpdateInfo( mpWindow& w, wxEvent& event ) override;
456
461 virtual void Plot( wxDC& dc, mpWindow& w ) override;
462
463protected:
464};
465
466
467// -----------------------------------------------------------------------------
468// mpLayer implementations - functions
469// -----------------------------------------------------------------------------
470
475#define mpALIGNMASK 0x03
477#define mpALIGN_RIGHT 0x00
479#define mpALIGN_CENTER 0x01
481#define mpALIGN_LEFT 0x02
483#define mpALIGN_TOP mpALIGN_RIGHT
485#define mpALIGN_BOTTOM mpALIGN_LEFT
487#define mpALIGN_BORDER_BOTTOM 0x04
489#define mpALIGN_BORDER_TOP 0x05
491#define mpALIGN_FAR_RIGHT 0x06
493#define mpX_NORMAL 0x00
495#define mpX_TIME 0x01
497#define mpX_HOURS 0x02
499#define mpX_DATE 0x03
501#define mpX_DATETIME 0x04
503#define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
505#define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
507#define mpALIGN_NE 0x00
509#define mpALIGN_NW 0x01
511#define mpALIGN_SW 0x02
513#define mpALIGN_SE 0x03
514
526{
527public:
531 mpFX( const wxString& name = wxEmptyString, int flags = mpALIGN_RIGHT );
532
538 virtual double GetY( double x ) const = 0;
539
544 virtual void Plot( wxDC& dc, mpWindow& w ) override;
545
546protected:
547 int m_flags; // !< Holds label alignment
548
549 DECLARE_DYNAMIC_CLASS( mpFX )
550};
551
558{
559public:
563 mpFY( const wxString& name = wxEmptyString, int flags = mpALIGN_TOP );
564
570 virtual double GetX( double y ) const = 0;
571
576 virtual void Plot( wxDC& dc, mpWindow& w ) override;
577
578protected:
579 int m_flags; // !< Holds label alignment
580
581 DECLARE_DYNAMIC_CLASS( mpFY )
582};
583
592{
593public:
597 mpFXY( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
598
602 virtual void Rewind() = 0;
603
609 virtual bool GetNextXY( double& x, double& y ) = 0;
610
611 virtual size_t GetCount() const = 0;
612
617 virtual void Plot( wxDC& dc, mpWindow& w ) override;
618
619 virtual void SetScale( mpScaleBase* scaleX, mpScaleBase* scaleY );
620
621 void UpdateScales();
622
623 double s2x( double plotCoordX ) const;
624 double s2y( double plotCoordY ) const;
625
626 double x2s( double x ) const;
627 double y2s( double y ) const;
628
629protected:
630 int m_flags; // !< Holds label alignment
631
632 // Data to calculate label positioning
633 wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
634 // int drawnPoints;
635 mpScaleBase* m_scaleX, * m_scaleY;
636
641 void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
642
643 DECLARE_DYNAMIC_CLASS( mpFXY )
644};
645
653{
654public:
658 mpProfile( const wxString& name = wxEmptyString, int flags = mpALIGN_TOP );
659
665 virtual double GetY( double x ) const = 0;
666
671 virtual void Plot( wxDC& dc, mpWindow& w ) override;
672
673protected:
674 int m_flags; // !< Holds label alignment
675
676 DECLARE_DYNAMIC_CLASS( mpProfile )
677};
678
681// -----------------------------------------------------------------------------
682// mpLayer implementations - furniture (scales, ...)
683// -----------------------------------------------------------------------------
684
696{
697public:
698 mpScaleBase();
699 virtual ~mpScaleBase() {};
700
701 virtual bool IsHorizontal() const = 0;
702
703 bool HasBBox() const override { return false; }
704
709 void SetAlign( int align ) { m_flags = align; };
710
711 void SetNameAlign( int align ) { m_nameFlags = align; }
712
716 void SetTicks( bool enable ) { m_ticks = enable; };
717
721 bool GetTicks() const { return m_ticks; };
722
723
724 // virtual double X2p( mpWindow &w, double x ) = 0;
725 // virtual double P2x( mpWindow &w, double x ) = 0;
726
727 void SetDataRange( double minV, double maxV )
728 {
729 m_rangeSet = true;
730 m_minV = minV;
731 m_maxV = maxV;
732 }
733
734 void GetDataRange( double& minV, double& maxV ) const
735 {
736 minV = m_minV;
737 maxV = m_maxV;
738 }
739
740 void ExtendDataRange( double minV, double maxV )
741 {
742 if( !m_rangeSet )
743 {
744 m_minV = minV;
745 m_maxV = maxV;
746 m_rangeSet = true;
747 }
748 else
749 {
750 m_minV = std::min( minV, m_minV );
751 m_maxV = std::max( maxV, m_maxV );
752 }
753
754 if( m_minV == m_maxV )
755 {
756 m_minV = m_minV - 1.0;
757 m_maxV = m_maxV + 1.0;
758 }
759 }
760
762 {
763 m_rangeSet = 0;
764 }
765
766 double AbsMaxValue() const
767 {
768 return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
769 }
770
771 double AbsVisibleMaxValue() const
772 {
773 return m_absVisibleMaxV;
774 }
775
776 virtual double TransformToPlot( double x ) const { return 0.0; };
777 virtual double TransformFromPlot( double xplot ) const { return 0.0; };
778
780 {
781 TickLabel( double pos_ = 0.0, const wxString& label_ = wxT("") ) :
782 pos( pos_ ), label( label_ ), pixelPos( 0 ), visible( true )
783 {}
784
785 double pos;
786 wxString label;
789 };
790
791 std::vector<TickLabel>& TickLabels() { return m_tickLabels; };
792
793protected:
794
795 void updateTickLabels( wxDC& dc, mpWindow& w );
796 void computeLabelExtents( wxDC& dc, mpWindow& w );
797
798 // virtual int getLabelDecimalDigits(int maxDigits) const;
799 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) {};
800 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) {};
801
802 int tickCount() const
803 {
804 return m_tickValues.size();
805 }
806
807 virtual int labelCount() const
808 {
809 return m_tickLabels.size();
810 }
811
812 virtual const wxString formatLabel( double value, int nDigits ) { return wxT( "" ); }
813 virtual void formatLabels() {};
814
815 virtual double getTickPos( int n ) const
816 {
817 return m_tickValues[n];
818 }
819
820 virtual double getLabelPos( int n ) const
821 {
822 return m_tickLabels[n].pos;
823 }
824
825 virtual wxString getLabel( int n ) const
826 {
827 return m_tickLabels[n].label;
828 }
829
830 std::vector<double> m_tickValues;
831 std::vector<TickLabel> m_tickLabels;
832
833 double m_offset, m_scale;
835 int m_flags; // !< Flag for axis alignment
837 bool m_ticks; // !< Flag to toggle between ticks or grid
838 double m_minV, m_maxV;
842};
843
845{
846public:
853 mpScaleXBase( const wxString& name = wxT("X"), int flags = mpALIGN_CENTER,
854 bool ticks = true, unsigned int type = mpX_NORMAL );
855 virtual ~mpScaleXBase() {};
856
857 virtual bool IsHorizontal() const override { return true; }
860 virtual void Plot( wxDC& dc, mpWindow& w ) override;
861
862 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
863
864 // unsigned int m_labelType; //!< Select labels mode: mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds
865 // wxString m_labelFormat; //!< Format string used to print labels
866
867 DECLARE_DYNAMIC_CLASS( mpScaleXBase )
868};
869
870
872{
873public:
879 mpScaleX( const wxString& name = wxT("X"), int flags = mpALIGN_CENTER,
880 bool ticks = true, unsigned int type = mpX_NORMAL );
881
884 // virtual void Plot(wxDC & dc, mpWindow & w);
885
886 // virtual double X2p( mpWindow &w, double x );
887 // virtual double P2x( mpWindow &w, double x );
888 virtual double TransformToPlot( double x ) const override;
889 virtual double TransformFromPlot( double xplot ) const override;
890
891protected:
892 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
893
894
895 DECLARE_DYNAMIC_CLASS( mpScaleX )
896};
897
898
900{
901public:
908 mpScaleXLog( const wxString& name = wxT("log(X)"), int flags = mpALIGN_CENTER,
909 bool ticks = true, unsigned int type = mpX_NORMAL );
910
911 virtual double TransformToPlot( double x ) const override;
912 virtual double TransformFromPlot( double xplot ) const override;
913
917 // virtual double X2p( mpWindow &w, double x );
918 // virtual double P2x( mpWindow &w, double x );
919
920protected:
921 void recalculateTicks( wxDC& dc, mpWindow& w ) override;
922
923 // int tickCount() const;
924 // int labelCount() const;
925 // const wxString getLabel( int n );
926 // double getTickPos( int n );
927 // double getLabelPos( int n );
928
929 void computeLabelExtents( wxDC& dc, mpWindow& w );
930
931
932 DECLARE_DYNAMIC_CLASS( mpScaleXLog )
933};
934
935
944{
945public:
950 mpScaleY( const wxString& name = wxT( "Y" ), int flags = mpALIGN_CENTER, bool ticks = true );
951
952 virtual bool IsHorizontal() const override { return false; }
953
957 virtual void Plot( wxDC& dc, mpWindow& w ) override;
958
963 virtual bool HasBBox() const override { return false; }
964
967 void SetAlign( int align ) { m_flags = align; };
968
971 void SetTicks( bool ticks ) { m_ticks = ticks; };
972
975 bool GetTicks() const { return m_ticks; };
976
977 virtual double TransformToPlot( double x ) const override;
978 virtual double TransformFromPlot( double xplot ) const override;
979
980
981 void SetMasterScale( mpScaleY* masterScale )
982 {
983 m_masterScale = masterScale;
984 }
985
986protected:
987 virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
988 virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
989
990 // virtual int tickCount() const;
991 // virtual int labelCount() const;
992 // virtual const wxString getLabel( int n );
993 // virtual double getTickPos( int n );
994 // virtual double getLabelPos( int n );
995 void computeLabelExtents( wxDC& dc, mpWindow& w );
996 void computeSlaveTicks( mpWindow& w );
997
999
1000 // double m_minV, m_maxV;
1001
1002 int m_flags; // !< Flag for axis alignment
1003 bool m_ticks; // !< Flag to toggle between ticks or grid
1004 // wxString m_labelFormat; //!< Format string used to print labels
1005
1006 DECLARE_DYNAMIC_CLASS( mpScaleY )
1007};
1008
1009// -----------------------------------------------------------------------------
1010// mpWindow
1011// -----------------------------------------------------------------------------
1012
1017#define mpMOUSEMODE_DRAG 0
1019#define mpMOUSEMODE_ZOOMBOX 1
1020
1023// WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, wxLayerList );
1024typedef std::deque<mpLayer*> wxLayerList;
1025
1048class WXDLLIMPEXP_MATHPLOT mpWindow : public wxWindow
1049{
1050public:
1052 mpWindow( wxWindow* parent, wxWindowID id,
1053 const wxPoint& pos = wxDefaultPosition,
1054 const wxSize& size = wxDefaultSize,
1055 long flags = 0 );
1056 ~mpWindow();
1057
1061 wxMenu* GetPopupMenu() { return &m_popmenu; }
1062
1070 bool AddLayer( mpLayer* layer, bool refreshDisplay = true );
1071
1080 bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true );
1081
1086 void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true );
1087
1088
1094 mpLayer* GetLayer( int position ) const;
1095
1100 const mpLayer* GetLayerByName( const wxString& name ) const;
1101 mpLayer* GetLayerByName( const wxString& name )
1102 {
1103 return const_cast<mpLayer*>( static_cast<const mpWindow*>( this )->GetLayerByName( name ) );
1104 }
1105
1110 double GetXscl() const { return m_scaleX; }
1111 double GetScaleX( void ) const { return m_scaleX; }; // Schaling's method: maybe another method exists with the same name
1112
1117 double GetYscl() const { return m_scaleY; }
1118 double GetScaleY( void ) const { return m_scaleY; } // Schaling's method: maybe another method exists with the same name
1119
1124 double GetXpos() const { return m_posX; }
1125 double GetPosX( void ) const { return m_posX; }
1126
1131 double GetYpos() const { return m_posY; }
1132 double GetPosY( void ) const { return m_posY; }
1133
1140 int GetScrX( void ) const { return m_scrX; }
1141 int GetXScreen( void ) const { return m_scrX; }
1142
1149 int GetScrY( void ) const { return m_scrY; }
1150 int GetYScreen( void ) const { return m_scrY; }
1151
1155 void SetScaleX( double scaleX );
1156
1160 void SetScaleY( double scaleY )
1161 {
1162 if( scaleY != 0 )
1163 m_scaleY = scaleY;
1164
1165 UpdateAll();
1166 }
1167
1171 void SetPosX( double posX ) { m_posX = posX; UpdateAll(); }
1172
1176 void SetPosY( double posY ) { m_posY = posY; UpdateAll(); }
1177
1182 void SetPos( double posX, double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
1183
1189 void SetScr( int scrX, int scrY ) { m_scrX = scrX; m_scrY = scrY; }
1190
1193 // double p2x(wxCoord pixelCoordX, bool drawOutside = true ); // { return m_posX + pixelCoordX/m_scaleX; }
1194 inline double p2x( wxCoord pixelCoordX ) { return m_posX + pixelCoordX / m_scaleX; }
1195
1198 // double p2y(wxCoord pixelCoordY, bool drawOutside = true ); //{ return m_posY - pixelCoordY/m_scaleY; }
1199 inline double p2y( wxCoord pixelCoordY ) { return m_posY - pixelCoordY / m_scaleY; }
1200
1203 // wxCoord x2p(double x, bool drawOutside = true); // { return (wxCoord) ( (x-m_posX) * m_scaleX); }
1204 inline wxCoord x2p( double x ) { return (wxCoord) ( (x - m_posX) * m_scaleX ); }
1205
1208 // wxCoord y2p(double y, bool drawOutside = true); // { return (wxCoord) ( (m_posY-y) * m_scaleY); }
1209 inline wxCoord y2p( double y ) { return (wxCoord) ( (m_posY - y) * m_scaleY ); }
1210
1211
1214 void EnableDoubleBuffer( bool enabled ) { m_enableDoubleBuffer = enabled; }
1215
1218 void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
1219
1222 void EnableMouseWheelPan( bool enabled ) { m_enableMouseWheelPan = enabled; }
1223
1229 void LockAspect( bool enable = true );
1230
1235 inline bool IsAspectLocked() const { return m_lockaspect; }
1236
1241 void Fit() override;
1242
1249 void Fit( double xMin, double xMax, double yMin, double yMax,
1250 wxCoord* printSizeX = NULL, wxCoord* printSizeY = NULL );
1251
1256 void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
1257 void ZoomIn( const wxPoint& centerPoint, double zoomFactor );
1258
1263 void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
1264 void ZoomOut( const wxPoint& centerPoint, double zoomFactor );
1265
1267 void ZoomInX();
1268
1270 void ZoomOutX();
1271
1273 void ZoomInY();
1274
1276 void ZoomOutY();
1277
1280 void ZoomRect( wxPoint p0, wxPoint p1 );
1281
1283 void UpdateAll();
1284
1285 // Added methods by Davide Rondini
1286
1291 unsigned int CountLayers() const;
1292
1295 unsigned int CountAllLayers() const { return m_layers.size(); };
1296
1297#if 0
1301 void PrintGraph(mpPrintout *print);
1302#endif
1303
1308 double GetDesiredXmin() const { return m_desiredXmin; }
1309
1314 double GetDesiredXmax() const { return m_desiredXmax; }
1315
1320 double GetDesiredYmin() const { return m_desiredYmin; }
1321
1326 double GetDesiredYmax() const { return m_desiredYmax; }
1327
1331 void GetBoundingBox( double* bbox ) const;
1332
1335 void SetMPScrollbars( bool status );
1336
1339 bool GetMPScrollbars() const { return m_enableScrollBars; };
1340
1346 bool SaveScreenshot( const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_BMP,
1347 wxSize imageSize = wxDefaultSize, bool fit = false );
1348
1354
1361 void SetMargins( int top, int right, int bottom, int left );
1362
1364 void SetMarginTop( int top ) { m_marginTop = top; };
1366 void SetMarginRight( int right ) { m_marginRight = right; };
1368 void SetMarginBottom( int bottom ) { m_marginBottom = bottom; };
1370 void SetMarginLeft( int left ) { m_marginLeft = left; };
1371
1373 int GetMarginTop() const { return m_marginTop; };
1375 int GetMarginRight() const { return m_marginRight; };
1377 int GetMarginBottom() const { return m_marginBottom; };
1379 int GetMarginLeft() const { return m_marginLeft; };
1380
1381#if 0
1385 // void EnableCoordTooltip(bool value = true);
1386
1390 // bool GetCoordTooltip() { return m_coordTooltip; };
1391#endif
1392
1396 mpInfoLayer* IsInsideInfoLayer( wxPoint& point );
1397
1401 void SetLayerVisible( const wxString& name, bool viewable );
1402
1406 bool IsLayerVisible( const wxString& name ) const;
1407
1411 void SetLayerVisible( const unsigned int position, bool viewable );
1412
1416 bool IsLayerVisible( unsigned int position ) const;
1417
1422 void SetColourTheme( const wxColour& bgColour,
1423 const wxColour& drawColour,
1424 const wxColour& axesColour );
1425
1428 const wxColour& GetAxesColour() { return m_axColour; };
1429
1431 void LimitView( bool aEnable )
1432 {
1433 m_enableLimitedView = aEnable;
1434 }
1435
1436protected:
1437 void OnPaint( wxPaintEvent& event ); // !< Paint handler, will plot all attached layers
1438 void OnSize( wxSizeEvent& event ); // !< Size handler, will update scroll bar sizes
1439
1440 // void OnScroll2 (wxScrollWinEvent &event); //!< Scroll handler, will move canvas
1441 void OnShowPopupMenu( wxMouseEvent& event ); // !< Mouse handler, will show context menu
1442 void OnMouseMiddleDown( wxMouseEvent& event ); // !< Mouse handler, for detecting when the user
1443
1444 // !< drags with the middle button or just "clicks" for the menu
1445 void OnCenter( wxCommandEvent& event ); // !< Context menu handler
1446 void OnFit( wxCommandEvent& event ); // !< Context menu handler
1447 void OnZoomIn( wxCommandEvent& event ); // !< Context menu handler
1448 void OnZoomOut( wxCommandEvent& event ); // !< Context menu handler
1449 void OnLockAspect( wxCommandEvent& event ); // !< Context menu handler
1450 void OnMouseWheel( wxMouseEvent& event ); // !< Mouse handler for the wheel
1451 void OnMagnify( wxMouseEvent& event ); // !< Pinch zoom handler
1452 void OnMouseMove( wxMouseEvent& event ); // !< Mouse handler for mouse motion (for pan)
1453 void OnMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
1454 void OnMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
1455 void OnScrollThumbTrack( wxScrollWinEvent& event ); // !< Scroll thumb on scroll bar moving
1456 void OnScrollPageUp( wxScrollWinEvent& event ); // !< Scroll page up
1457 void OnScrollPageDown( wxScrollWinEvent& event ); // !< Scroll page down
1458 void OnScrollLineUp( wxScrollWinEvent& event ); // !< Scroll line up
1459 void OnScrollLineDown( wxScrollWinEvent& event ); // !< Scroll line down
1460 void OnScrollTop( wxScrollWinEvent& event ); // !< Scroll to top
1461 void OnScrollBottom( wxScrollWinEvent& event ); // !< Scroll to bottom
1462
1463 void DoScrollCalc( const int position, const int orientation );
1464
1465 void DoZoomInXCalc( const int staticXpixel );
1466 void DoZoomInYCalc( const int staticYpixel );
1467 void DoZoomOutXCalc( const int staticXpixel );
1468 void DoZoomOutYCalc( const int staticYpixel );
1469
1470 bool CheckXLimits( double& desiredMax, double& desiredMin ) const
1471 {
1472 return !( m_enableLimitedView
1473 && (desiredMax > m_maxX - m_marginRight / m_scaleX
1474 || desiredMin < m_minX - m_marginLeft / m_scaleX) );
1475 }
1476
1477 bool CheckYLimits( double& desiredMax, double& desiredMin ) const
1478 {
1479 return !( m_enableLimitedView
1480 && (desiredMax > m_maxY + m_marginBottom / m_scaleY
1481 || desiredMin < m_minY + m_marginTop / m_scaleY) );
1482 }
1483
1484 void AdjustLimitedView();
1485
1489 virtual bool UpdateBBox();
1490
1494 virtual bool SetXView( double pos, double desiredMax, double desiredMin );
1495
1499 virtual bool SetYView( double pos, double desiredMax, double desiredMin );
1500
1501 // wxList m_layers; //!< List of attached plot layers
1502 wxLayerList m_layers; // !< List of attached plot layers
1503 wxMenu m_popmenu; // !< Canvas' context menu
1504 bool m_lockaspect; // !< Scale aspect is locked or not
1505 // bool m_coordTooltip; //!< Selects whether to show coordinate tooltip
1506 wxColour m_bgColour; // !< Background Colour
1507 wxColour m_fgColour; // !< Foreground Colour
1508 wxColour m_axColour; // !< Axes Colour
1509
1510 double m_minX; // !< Global layer bounding box, left border incl.
1511 double m_maxX; // !< Global layer bounding box, right border incl.
1512 double m_minY; // !< Global layer bounding box, bottom border incl.
1513 double m_maxY; // !< Global layer bounding box, top border incl.
1514 double m_scaleX; // !< Current view's X scale
1515 double m_scaleY; // !< Current view's Y scale
1516 double m_posX; // !< Current view's X position
1517 double m_posY; // !< Current view's Y position
1518 int m_scrX; // !< Current view's X dimension
1519 int m_scrY; // !< Current view's Y dimension
1520 int m_clickedX; // !< Last mouse click X position, for centering and zooming the view
1521 int m_clickedY; // !< Last mouse click Y position, for centering and zooming the view
1522
1526 double m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax;
1527
1528 int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
1529
1530 int m_last_lx, m_last_ly; // !< For double buffering
1531 wxMemoryDC m_buff_dc; // !< For double buffering
1532 wxBitmap* m_buff_bmp; // !< For double buffering
1533 bool m_enableDoubleBuffer; // !< For double buffering
1534 bool m_enableMouseNavigation; // !< For pan/zoom with the mouse.
1535 bool m_enableMouseWheelPan; // !< Trackpad pan/zoom
1537 wxPoint m_mouseMClick; // !< For the middle button "drag" feature
1538 wxPoint m_mouseLClick; // !< Starting coords for rectangular zoom selection
1540 wxPoint m_scroll;
1541 mpInfoLayer* m_movingInfoLayer; // !< For moving info layers over the window area
1544 DECLARE_DYNAMIC_CLASS( mpWindow )
1545 DECLARE_EVENT_TABLE()
1546};
1547
1548// -----------------------------------------------------------------------------
1549// mpFXYVector - provided by Jose Luis Blanco
1550// -----------------------------------------------------------------------------
1551
1572{
1573public:
1577 mpFXYVector( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
1578
1579 virtual ~mpFXYVector() {}
1580
1585 virtual void SetData( const std::vector<double>& xs, const std::vector<double>& ys );
1586
1590 void Clear();
1591
1592protected:
1595 std::vector<double> m_xs, m_ys;
1596
1599 size_t m_index;
1600
1603 double m_minX, m_maxX, m_minY, m_maxY;
1604
1608 void Rewind() override;
1609
1615 bool GetNextXY( double& x, double& y ) override;
1616
1617 size_t GetCount() const override;
1618
1619public:
1622 double GetMinX() const override { return m_minX; }
1623
1626 double GetMinY() const override { return m_minY; }
1627
1630 double GetMaxX() const override { return m_maxX; }
1631
1634 double GetMaxY() const override { return m_maxY; }
1635
1636protected:
1637
1638 DECLARE_DYNAMIC_CLASS( mpFXYVector )
1639};
1640
1641
1642#if 0
1643
1644class WXDLLIMPEXP_MATHPLOT mpFSemiLogXVector : public mpFXYVector
1645{
1646public:
1650 mpFSemiLogXVector( wxString name = wxEmptyString, int flags = mpALIGN_NE );
1651
1652 virtual ~mpFSemiLogXVector() {}
1653
1659 DECLARE_DYNAMIC_CLASS( mpFSemiLogXVector )
1660};
1661#endif
1662
1663// -----------------------------------------------------------------------------
1664// mpText - provided by Val Greene
1665// -----------------------------------------------------------------------------
1666
1674{
1675public:
1679 mpText( const wxString& name = wxT("Title"), int offsetx = 5, int offsety = 50 );
1680
1683 virtual void Plot( wxDC& dc, mpWindow& w ) override;
1684
1686 virtual bool HasBBox() const override { return false; }
1687
1688protected:
1689 int m_offsetx; // !< Holds offset for X in percentage
1690 int m_offsety; // !< Holds offset for Y in percentage
1691
1692 DECLARE_DYNAMIC_CLASS( mpText )
1693};
1694
1695
1696// -----------------------------------------------------------------------------
1697// mpPrintout - provided by Davide Rondini
1698// -----------------------------------------------------------------------------
1699
1704class WXDLLIMPEXP_MATHPLOT mpPrintout : public wxPrintout
1705{
1706public:
1707 mpPrintout( mpWindow* drawWindow, const wxChar* title = _T("wxMathPlot print output") );
1708 virtual ~mpPrintout() {};
1709
1710 void SetDrawState( bool drawState ) { drawn = drawState; };
1711 bool OnPrintPage( int page ) override;
1712 bool HasPage( int page ) override;
1713
1714private:
1715 bool drawn;
1717};
1718
1719
1720// -----------------------------------------------------------------------------
1721// mpMovableObject - provided by Jose Luis Blanco
1722// -----------------------------------------------------------------------------
1730{
1731public:
1735 m_flags( 0 ),
1736 m_reference_x( 0 ),
1737 m_reference_y( 0 ),
1738 m_reference_phi( 0 ),
1739 m_shape_xs( 0 ),
1740 m_shape_ys( 0 ),
1741 m_bbox_min_x( 0 ),
1742 m_bbox_max_x( 0 ),
1743 m_bbox_min_y( 0 ),
1744 m_bbox_max_y( 0 )
1745 {
1746 m_type = mpLAYER_PLOT;
1747 }
1748
1749 virtual ~mpMovableObject() {};
1750
1753 void GetCoordinateBase( double& x, double& y, double& phi ) const
1754 {
1755 x = m_reference_x;
1756 y = m_reference_y;
1757 phi = m_reference_phi;
1758 }
1759
1762 void SetCoordinateBase( double x, double y, double phi = 0 )
1763 {
1764 m_reference_x = x;
1765 m_reference_y = y;
1766 m_reference_phi = phi;
1767 m_flags = mpALIGN_NE;
1768 ShapeUpdated();
1769 }
1770
1771 virtual bool HasBBox() const override { return m_trans_shape_xs.size()!=0; }
1772
1775 virtual double GetMinX() const override { return m_bbox_min_x; }
1776
1779 virtual double GetMaxX() const override { return m_bbox_max_x; }
1780
1783 virtual double GetMinY() const override { return m_bbox_min_y; }
1784
1787 virtual double GetMaxY() const override { return m_bbox_max_y; }
1788
1789 virtual void Plot( wxDC& dc, mpWindow& w ) override;
1790
1794 void SetAlign( int align ) { m_flags = align; };
1795
1796protected:
1797 int m_flags; // !< Holds label alignment
1798
1801 double m_reference_x, m_reference_y, m_reference_phi;
1802
1806 void TranslatePoint( double x, double y, double& out_x, double& out_y );
1807
1811 std::vector<double> m_shape_xs, m_shape_ys;
1812
1816 std::vector<double> m_trans_shape_xs, m_trans_shape_ys;
1817
1821 double m_bbox_min_x, m_bbox_max_x, m_bbox_min_y, m_bbox_max_y;
1822
1827 void ShapeUpdated();
1828};
1829
1830// -----------------------------------------------------------------------------
1831// mpCovarianceEllipse - provided by Jose Luis Blanco
1832// -----------------------------------------------------------------------------
1845{
1846public:
1851 mpCovarianceEllipse( double cov_00 = 1,
1852 double cov_11 = 1,
1853 double cov_01 = 0,
1854 double quantiles = 2,
1855 int segments = 32,
1856 const wxString& layerName = wxT("") ) :
1857 m_cov_00( cov_00 ),
1858 m_cov_11( cov_11 ),
1859 m_cov_01( cov_01 ),
1860 m_quantiles( quantiles ),
1861 m_segments( segments )
1862 {
1863 m_continuous = true;
1864 m_name = layerName;
1865 RecalculateShape();
1866 m_type = mpLAYER_PLOT;
1867 }
1868
1870
1871 double GetQuantiles() const { return m_quantiles; }
1872
1875 void SetQuantiles( double q )
1876 {
1877 m_quantiles = q;
1878 RecalculateShape();
1879 }
1880
1881 void SetSegments( int segments ) { m_segments = segments; }
1882 int GetSegments() const { return m_segments; }
1883
1886 void GetCovarianceMatrix( double& cov_00, double& cov_01, double& cov_11 ) const
1887 {
1888 cov_00 = m_cov_00;
1889 cov_01 = m_cov_01;
1890 cov_11 = m_cov_11;
1891 }
1892
1895 void SetCovarianceMatrix( double cov_00, double cov_01, double cov_11 )
1896 {
1897 m_cov_00 = cov_00;
1898 m_cov_01 = cov_01;
1899 m_cov_11 = cov_11;
1900 RecalculateShape();
1901 }
1902
1903protected:
1906 double m_cov_00, m_cov_11, m_cov_01;
1908
1912
1915 void RecalculateShape();
1916};
1917
1918// -----------------------------------------------------------------------------
1919// mpPolygon - provided by Jose Luis Blanco
1920// -----------------------------------------------------------------------------
1926{
1927public:
1930 mpPolygon( const wxString& layerName = wxT("") )
1931 {
1932 m_continuous = true;
1933 m_name = layerName;
1934 }
1935
1936 virtual ~mpPolygon() {}
1937
1943 void setPoints( const std::vector<double>& points_xs,
1944 const std::vector<double>& points_ys,
1945 bool closedShape = true );
1946};
1947
1948// -----------------------------------------------------------------------------
1949// mpMovableObject - provided by Jose Luis Blanco
1950// -----------------------------------------------------------------------------
1958{
1959public:
1963 {
1964 m_min_x = m_max_x =
1965 m_min_y = m_max_y = 0;
1966 m_scaledBitmap_offset_x = 0;
1967 m_scaledBitmap_offset_y = 0;
1968 m_validImg = false;
1969 m_type = mpLAYER_BITMAP;
1970 }
1971
1972 virtual ~mpBitmapLayer() {};
1973
1976 void GetBitmapCopy( wxImage& outBmp ) const;
1977
1985 void SetBitmap( const wxImage& inBmp, double x, double y, double lx, double ly );
1986
1987 virtual bool HasBBox() const override { return true; }
1988
1991 virtual double GetMinX() const override { return m_min_x; }
1992
1995 virtual double GetMaxX() const override { return m_max_x; }
1996
1999 virtual double GetMinY() const override { return m_min_y; }
2000
2003 virtual double GetMaxY() const override { return m_max_y; }
2004
2005 virtual void Plot( wxDC& dc, mpWindow& w ) override;
2006
2010 void SetAlign( int align ) { m_flags = align; };
2011
2012protected:
2013 int m_flags; // !< Holds label alignment
2014
2017 wxImage m_bitmap;
2019 wxCoord m_scaledBitmap_offset_x, m_scaledBitmap_offset_y;
2020
2022
2025 double m_min_x, m_max_x, m_min_y, m_max_y;
2026};
2027
2030#endif // _MP_MATHPLOT_H_
const char * name
Definition: DXF_plotter.cpp:56
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
Definition: mathplot.h:1958
bool m_validImg
Definition: mathplot.h:2021
virtual double GetMaxX() const override
Get inclusive right border of bounding box.
Definition: mathplot.h:1995
wxBitmap m_scaledBitmap
Definition: mathplot.h:2018
virtual double GetMinX() const override
Get inclusive left border of bounding box.
Definition: mathplot.h:1991
wxImage m_bitmap
The internal copy of the Bitmap:
Definition: mathplot.h:2017
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:1987
virtual ~mpBitmapLayer()
Definition: mathplot.h:1972
void SetAlign(int align)
Set label axis alignment.
Definition: mathplot.h:2010
mpBitmapLayer()
Default constructor.
Definition: mathplot.h:1962
virtual double GetMinY() const override
Get inclusive bottom border of bounding box.
Definition: mathplot.h:1999
wxCoord m_scaledBitmap_offset_x
Definition: mathplot.h:2019
double m_max_x
Definition: mathplot.h:2025
virtual double GetMaxY() const override
Get inclusive top border of bounding box.
Definition: mathplot.h:2003
A 2D ellipse, described by a 2x2 covariance matrix.
Definition: mathplot.h:1845
void SetSegments(int segments)
Definition: mathplot.h:1881
int GetSegments() const
Definition: mathplot.h:1882
double m_cov_00
The elements of the matrix (only 3 since cov(0,1)=cov(1,0) in any positive definite matrix).
Definition: mathplot.h:1906
void SetQuantiles(double q)
Set how many "quantiles" to draw, that is, the confidence interval of the ellipse (see above).
Definition: mathplot.h:1875
void SetCovarianceMatrix(double cov_00, double cov_01, double cov_11)
Changes the covariance matrix:
Definition: mathplot.h:1895
double GetQuantiles() const
Definition: mathplot.h:1871
int m_segments
The number of line segments that build up the ellipse.
Definition: mathplot.h:1911
void GetCovarianceMatrix(double &cov_00, double &cov_01, double &cov_11) const
Returns the elements of the current covariance matrix:
Definition: mathplot.h:1886
mpCovarianceEllipse(double cov_00=1, double cov_11=1, double cov_01=0, double quantiles=2, int segments=32, const wxString &layerName=wxT(""))
Default constructor.
Definition: mathplot.h:1851
virtual ~mpCovarianceEllipse()
Definition: mathplot.h:1869
A class providing graphs functionality for a 2D plot (either continuous or a set of points),...
Definition: mathplot.h:1572
double GetMaxY() const override
Returns the actual maximum Y data (loaded in SetData).
Definition: mathplot.h:1634
double GetMinY() const override
Returns the actual minimum Y data (loaded in SetData).
Definition: mathplot.h:1626
double GetMinX() const override
Returns the actual minimum X data (loaded in SetData).
Definition: mathplot.h:1622
std::vector< double > m_xs
The internal copy of the set of data to draw.
Definition: mathplot.h:1595
double m_maxX
Definition: mathplot.h:1603
double GetMaxX() const override
Returns the actual maximum X data (loaded in SetData).
Definition: mathplot.h:1630
virtual ~mpFXYVector()
Definition: mathplot.h:1579
size_t m_index
The internal counter for the "GetNextXY" interface.
Definition: mathplot.h:1599
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,...
Definition: mathplot.h:592
mpScaleBase * m_scaleX
Definition: mathplot.h:635
wxCoord maxDrawX
Definition: mathplot.h:633
virtual void Rewind()=0
Rewind value enumeration with mpFXY::GetNextXY.
virtual size_t GetCount() const =0
int m_flags
Definition: mathplot.h:630
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:526
virtual double GetY(double x) const =0
Get function value for argument.
int m_flags
Definition: mathplot.h:547
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:558
int m_flags
Definition: mathplot.h:579
virtual double GetX(double y) const =0
Get function value for argument.
Implements an overlay box which shows the mouse coordinates in plot units.
Definition: mathplot.h:407
wxString m_content
Definition: mathplot.h:431
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
Definition: mathplot.h:336
const wxRect & GetRectangle() const
Returns the current rectangle coordinates.
Definition: mathplot.h:392
virtual bool HasBBox() const override
mpInfoLayer has not bounding box.
Definition: mathplot.h:357
wxPoint m_reference
Definition: mathplot.h:396
wxRect m_dim
Definition: mathplot.h:395
virtual bool IsInfo() const override
Specifies that this is an Info box layer.
Definition: mathplot.h:368
wxBrush m_brush
Definition: mathplot.h:397
int m_winX
Definition: mathplot.h:398
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
Definition: mathplot.h:438
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:294
wxFont m_font
Definition: mathplot.h:314
bool m_drawOutsideMargins
Definition: mathplot.h:320
bool IsVisible() const
Checks whether the layer is visible or not.
Definition: mathplot.h:298
const wxString & GetName() const
Get layer name.
Definition: mathplot.h:238
virtual ~mpLayer()
Definition: mathplot.h:152
virtual double GetMinY() const
Get inclusive bottom border of bounding box.
Definition: mathplot.h:185
bool GetContinuity() const
Gets the 'continuity' property of the layer.
Definition: mathplot.h:258
bool m_continuous
Definition: mathplot.h:318
void SetPen(wxPen pen)
Set layer pen.
Definition: mathplot.h:277
bool m_showName
Definition: mathplot.h:319
bool m_visible
Definition: mathplot.h:322
virtual bool IsInfo() const
Check whether the layer is an info box.
Definition: mathplot.h:170
bool GetDrawOutsideMargins()
Get Draw mode: inside or outside margins.
Definition: mathplot.h:285
void SetContinuity(bool continuity)
Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points...
Definition: mathplot.h:253
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
Definition: mathplot.h:262
void SetFont(wxFont &font)
Set layer font.
Definition: mathplot.h:272
const wxFont & GetFont() const
Get font set for this layer.
Definition: mathplot.h:243
const wxPen & GetPen() const
Get pen set for this layer.
Definition: mathplot.h:248
mpLayerType m_type
Definition: mathplot.h:321
void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:302
void SetBrush(wxBrush brush)
Set layer brush.
Definition: mathplot.h:310
wxString m_name
Definition: mathplot.h:317
wxBrush m_brush
Definition: mathplot.h:316
wxPen m_pen
Definition: mathplot.h:315
virtual double GetMaxX() const
Get inclusive right border of bounding box.
Definition: mathplot.h:180
const wxBrush & GetBrush() const
Get brush set for this layer.
Definition: mathplot.h:306
virtual double GetMinX() const
Get inclusive left border of bounding box.
Definition: mathplot.h:175
virtual void SetName(wxString name)
Set layer name.
Definition: mathplot.h:267
virtual double GetMaxY() const
Get inclusive top border of bounding box.
Definition: mathplot.h:190
virtual bool HasBBox() const
Check whether this layer has a bounding box.
Definition: mathplot.h:161
void SetDrawOutsideMargins(bool drawModeOutside)
Set Draw mode: inside or outside margins.
Definition: mathplot.h:281
This virtual class represents objects that can be moved to an arbitrary 2D location+rotation.
Definition: mathplot.h:1730
void SetAlign(int align)
Set label axis alignment.
Definition: mathplot.h:1794
void GetCoordinateBase(double &x, double &y, double &phi) const
Get the current coordinate transformation.
Definition: mathplot.h:1753
double m_bbox_max_x
Definition: mathplot.h:1821
virtual double GetMaxY() const override
Get inclusive top border of bounding box.
Definition: mathplot.h:1787
std::vector< double > m_trans_shape_xs
The buffer for the translated & rotated points (to avoid recomputing them with each mpWindow refresh)...
Definition: mathplot.h:1816
virtual double GetMinX() const override
Get inclusive left border of bounding box.
Definition: mathplot.h:1775
virtual ~mpMovableObject()
Definition: mathplot.h:1749
mpMovableObject()
Default constructor (sets location and rotation to (0,0,0))
Definition: mathplot.h:1734
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:1771
void SetCoordinateBase(double x, double y, double phi=0)
Set the coordinate transformation (phi in radians, 0 means no rotation).
Definition: mathplot.h:1762
virtual double GetMinY() const override
Get inclusive bottom border of bounding box.
Definition: mathplot.h:1783
double m_reference_phi
Definition: mathplot.h:1801
std::vector< double > m_shape_xs
This contains the object points, in local coordinates (to be transformed by the current transformatio...
Definition: mathplot.h:1811
virtual double GetMaxX() const override
Get inclusive right border of bounding box.
Definition: mathplot.h:1779
An arbitrary polygon, descendant of mpMovableObject.
Definition: mathplot.h:1926
mpPolygon(const wxString &layerName=wxT(""))
Default constructor.
Definition: mathplot.h:1930
virtual ~mpPolygon()
Definition: mathplot.h:1936
Printout class used by mpWindow to draw in the objects to be printed.
Definition: mathplot.h:1705
bool drawn
Definition: mathplot.h:1715
mpWindow * plotWindow
Definition: mathplot.h:1716
virtual ~mpPrintout()
Definition: mathplot.h:1708
void SetDrawState(bool drawState)
Definition: mathplot.h:1710
Abstract base class providing plot and labeling functionality for functions F:Y->X.
Definition: mathplot.h:653
int m_flags
Definition: mathplot.h:674
virtual double GetY(double x) const =0
Get function value for argument.
Plot layer implementing a x-scale ruler.
Definition: mathplot.h:696
void SetNameAlign(int align)
Definition: mathplot.h:711
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
Definition: mathplot.h:800
double m_offset
Definition: mathplot.h:833
double AbsMaxValue() const
Definition: mathplot.h:766
void GetDataRange(double &minV, double &maxV) const
Definition: mathplot.h:734
std::vector< double > m_tickValues
Definition: mathplot.h:830
bool m_rangeSet
Definition: mathplot.h:839
double AbsVisibleMaxValue() const
Definition: mathplot.h:771
bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:703
void SetAlign(int align)
Set X axis alignment.
Definition: mathplot.h:709
std::vector< TickLabel > & TickLabels()
Definition: mathplot.h:791
void SetTicks(bool enable)
Set X axis ticks or grid.
Definition: mathplot.h:716
virtual double TransformToPlot(double x) const
Definition: mathplot.h:776
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:831
virtual void formatLabels()
Definition: mathplot.h:813
int m_maxLabelHeight
Definition: mathplot.h:840
virtual wxString getLabel(int n) const
Definition: mathplot.h:825
virtual bool IsHorizontal() const =0
virtual double getTickPos(int n) const
Definition: mathplot.h:815
double m_maxV
Definition: mathplot.h:838
void ResetDataRange()
Definition: mathplot.h:761
int tickCount() const
Definition: mathplot.h:802
int m_maxLabelWidth
Definition: mathplot.h:841
bool GetTicks() const
Get X axis ticks or grid.
Definition: mathplot.h:721
virtual const wxString formatLabel(double value, int nDigits)
Definition: mathplot.h:812
virtual double getLabelPos(int n) const
Definition: mathplot.h:820
double m_absVisibleMaxV
Definition: mathplot.h:834
bool m_ticks
Definition: mathplot.h:837
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV)
Definition: mathplot.h:799
int m_flags
Definition: mathplot.h:835
int m_nameFlags
Definition: mathplot.h:836
virtual ~mpScaleBase()
Definition: mathplot.h:699
void ExtendDataRange(double minV, double maxV)
Definition: mathplot.h:740
void SetDataRange(double minV, double maxV)
Definition: mathplot.h:727
virtual double TransformFromPlot(double xplot) const
Definition: mathplot.h:777
virtual int labelCount() const
Definition: mathplot.h:807
virtual ~mpScaleXBase()
Definition: mathplot.h:855
virtual bool IsHorizontal() const override
Definition: mathplot.h:857
void computeLabelExtents(wxDC &dc, mpWindow &w)
Plot layer implementing a y-scale ruler.
Definition: mathplot.h:944
int m_flags
Definition: mathplot.h:1002
mpScaleY * m_masterScale
Definition: mathplot.h:998
void SetTicks(bool ticks)
Set Y axis ticks or grid.
Definition: mathplot.h:971
void computeLabelExtents(wxDC &dc, mpWindow &w)
virtual bool IsHorizontal() const override
Definition: mathplot.h:952
void SetMasterScale(mpScaleY *masterScale)
Definition: mathplot.h:981
bool GetTicks() const
Get Y axis ticks or grid.
Definition: mathplot.h:975
bool m_ticks
Definition: mathplot.h:1003
void SetAlign(int align)
Set Y axis alignment.
Definition: mathplot.h:967
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Definition: mathplot.h:963
Plot layer implementing a text string.
Definition: mathplot.h:1674
virtual bool HasBBox() const override
mpText should not be used for scaling decisions.
Definition: mathplot.h:1686
int m_offsetx
Definition: mathplot.h:1689
int m_offsety
Definition: mathplot.h:1690
Canvas for plotting mpLayer implementations.
Definition: mathplot.h:1049
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1541
bool m_zooming
Definition: mathplot.h:1542
double m_maxY
Definition: mathplot.h:1513
double m_posY
Definition: mathplot.h:1517
int GetMarginLeft() const
Definition: mathplot.h:1379
bool m_enableMouseNavigation
Definition: mathplot.h:1534
void DoZoomInYCalc(const int staticYpixel)
void EnableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
Definition: mathplot.h:1218
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1140
void SetMarginLeft(int left)
Set the left margin.
Definition: mathplot.h:1370
double GetYscl() const
Get current view's Y scale.
Definition: mathplot.h:1117
const wxColour & GetAxesColour()
Get axes draw colour.
Definition: mathplot.h:1428
double m_desiredXmax
Definition: mathplot.h:1526
int m_last_lx
Definition: mathplot.h:1530
wxPoint m_scroll
Definition: mathplot.h:1540
bool m_enableMouseWheelPan
Definition: mathplot.h:1535
double m_minY
Definition: mathplot.h:1512
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1194
int GetXScreen(void) const
Definition: mathplot.h:1141
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1199
wxMemoryDC m_buff_dc
Definition: mathplot.h:1531
double m_maxX
Definition: mathplot.h:1511
void SetMarginRight(int right)
Set the right margin.
Definition: mathplot.h:1366
int m_marginBottom
Definition: mathplot.h:1528
void LimitView(bool aEnable)
Limit zooming & panning to the area used by the plots.
Definition: mathplot.h:1431
int m_clickedY
Definition: mathplot.h:1521
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1204
wxColour m_bgColour
Definition: mathplot.h:1506
double GetYpos() const
Get current view's Y position.
Definition: mathplot.h:1131
double m_posX
Definition: mathplot.h:1516
wxPoint m_mouseLClick
Definition: mathplot.h:1538
void SetMarginTop(int top)
Set the top margin.
Definition: mathplot.h:1364
double GetPosY(void) const
Definition: mathplot.h:1132
bool m_lockaspect
Definition: mathplot.h:1504
bool m_enableScrollBars
Definition: mathplot.h:1539
void SetPosX(double posX)
Set current view's X position and refresh display.
Definition: mathplot.h:1171
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:1326
int GetMarginTop() const
Definition: mathplot.h:1373
double m_scaleY
Definition: mathplot.h:1515
void SetMarginBottom(int bottom)
Set the bottom margin.
Definition: mathplot.h:1368
double GetScaleX(void) const
Definition: mathplot.h:1111
void SetPosY(double posY)
Set current view's Y position and refresh display.
Definition: mathplot.h:1176
void SetScaleY(double scaleY)
Set current view's Y scale and refresh display.
Definition: mathplot.h:1160
void OnMagnify(wxMouseEvent &event)
void ZoomInY()
Zoom in current view along Y and refresh display.
wxColour m_fgColour
Definition: mathplot.h:1507
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:1320
double m_minX
Definition: mathplot.h:1510
double GetScaleY(void) const
Definition: mathplot.h:1118
bool IsAspectLocked() const
Checks whether the X/Y scale aspect is locked.
Definition: mathplot.h:1235
void ZoomOutY()
Zoom out current view along Y and refresh display.
bool CheckYLimits(double &desiredMax, double &desiredMin) const
Definition: mathplot.h:1477
wxRect m_zoomRect
Definition: mathplot.h:1543
wxLayerList m_layers
Definition: mathplot.h:1502
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
Definition: mathplot.h:1209
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:1314
wxMenu m_popmenu
Definition: mathplot.h:1503
bool m_enableLimitedView
Definition: mathplot.h:1536
int m_clickedX
Definition: mathplot.h:1520
bool CheckXLimits(double &desiredMax, double &desiredMin) const
Definition: mathplot.h:1470
wxBitmap * m_buff_bmp
Definition: mathplot.h:1532
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
Definition: mathplot.h:1061
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:1308
void DoZoomOutXCalc(const int staticXpixel)
double GetXpos() const
Get current view's X position.
Definition: mathplot.h:1124
wxPoint m_mouseMClick
Definition: mathplot.h:1537
void SetMPScrollbars(bool status)
Enable/disable scrollbars.
double GetXscl() const
Get current view's X scale.
Definition: mathplot.h:1110
int GetMarginRight() const
Definition: mathplot.h:1375
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
Definition: mathplot.h:1189
int GetMarginBottom() const
Definition: mathplot.h:1377
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
Definition: mathplot.h:1214
wxColour m_axColour
Definition: mathplot.h:1508
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:1353
mpLayer * GetLayerByName(const wxString &name)
Definition: mathplot.h:1101
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1149
void ZoomOutX()
Zoom out current view along X and refresh display.
void DoZoomOutYCalc(const int staticYpixel)
double m_scaleX
Definition: mathplot.h:1514
bool m_enableDoubleBuffer
Definition: mathplot.h:1533
void EnableMouseWheelPan(bool enabled)
Enable/disable trackpad friendly panning (2-axis scroll wheel)
Definition: mathplot.h:1222
unsigned int CountAllLayers() const
Counts the number of plot layers, whether or not they have a bounding box.
Definition: mathplot.h:1295
double GetPosX(void) const
Definition: mathplot.h:1125
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
Definition: mathplot.h:1182
int m_scrY
Definition: mathplot.h:1519
int GetYScreen(void) const
Definition: mathplot.h:1150
bool GetMPScrollbars() const
Get scrollbars status.
Definition: mathplot.h:1339
int m_scrX
Definition: mathplot.h:1518
class WXDLLIMPEXP_MATHPLOT mpText
Definition: mathplot.h:109
class WXDLLIMPEXP_MATHPLOT mpFY
Definition: mathplot.h:103
class WXDLLIMPEXP_MATHPLOT mpWindow
Definition: mathplot.h:108
class WXDLLIMPEXP_MATHPLOT mpPrintout
Definition: mathplot.h:110
class WXDLLIMPEXP_MATHPLOT mpFXYVector
Definition: mathplot.h:105
__mp_Layer_Type
Definition: mathplot.h:127
@ mpLAYER_INFO
Definition: mathplot.h:131
@ mpLAYER_BITMAP
Definition: mathplot.h:132
@ mpLAYER_UNDEF
Definition: mathplot.h:128
@ mpLAYER_AXIS
Definition: mathplot.h:129
@ mpLAYER_PLOT
Definition: mathplot.h:130
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:477
enum __mp_Layer_Type mpLayerType
std::deque< mpLayer * > wxLayerList
Define the type for the list of layers inside mpWindow.
Definition: mathplot.h:1024
class WXDLLIMPEXP_MATHPLOT mpFXY
Definition: mathplot.h:104
@ mpID_FIT
Definition: mathplot.h:115
@ mpID_LOCKASPECT
Definition: mathplot.h:119
@ mpID_ZOOM_IN
Definition: mathplot.h:116
@ mpID_CENTER
Definition: mathplot.h:118
@ mpID_ZOOM_OUT
Definition: mathplot.h:117
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:479
#define mpALIGN_TOP
Aligns label to the top.
Definition: mathplot.h:483
#define WXDLLIMPEXP_MATHPLOT
wxMathPlot is a framework for mathematical graph plotting in wxWindows.
Definition: mathplot.h:61
class WXDLLIMPEXP_MATHPLOT mpLayer
Definition: mathplot.h:101
class WXDLLIMPEXP_MATHPLOT mpFX
Definition: mathplot.h:102
class WXDLLIMPEXP_MATHPLOT mpScaleX
Definition: mathplot.h:106
class WXDLLIMPEXP_MATHPLOT mpScaleY
Definition: mathplot.h:107
#define mpX_NORMAL
Set label for X axis in normal mode.
Definition: mathplot.h:493
#define mpALIGN_NE
Aligns label to north-east.
Definition: mathplot.h:507
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:418
TickLabel(double pos_=0.0, const wxString &label_=wxT(""))
Definition: mathplot.h:781
constexpr int delta