14#ifndef _MP_MATHPLOT_H_
15#define _MP_MATHPLOT_H_
58#ifdef mathplot_EXPORTS
59#define WXDLLIMPEXP_MATHPLOT WXEXPORT
60#define WXDLLIMPEXP_DATA_MATHPLOT( type ) WXEXPORT type
62#define WXDLLIMPEXP_MATHPLOT
63#define WXDLLIMPEXP_DATA_MATHPLOT( type ) type
69#include <wx/scrolwin.h>
71#include <wx/dynarray.h>
73#include <wx/dcmemory.h>
88#define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
95#define X_BORDER_SEPARATION 40
96#define Y_BORDER_SEPARATION 60
171 virtual bool IsInfo()
const {
return false; };
176 virtual double GetMinX()
const {
return -1.0; }
181 virtual double GetMaxX()
const {
return 1.0; }
186 virtual double GetMinY()
const {
return -1.0; }
191 virtual double GetMaxY()
const {
return 1.0; }
239 const wxString&
GetName()
const {
return m_name; }
243 return m_displayName.IsEmpty() ? m_name : m_displayName;
249 const wxFont&
GetFont()
const {
return m_font; }
254 const wxPen&
GetPen()
const {
return m_pen; }
278 void SetFont(
const wxFont& font ) { m_font = font; }
283 void SetPen(
const wxPen& pen ) { m_pen = pen; }
299 const wxBrush&
GetBrush()
const {
return m_brush; };
303 void SetBrush(
const wxBrush& brush ) { m_brush = brush; };
317 DECLARE_DYNAMIC_CLASS(
mpLayer )
338 mpInfoLayer( wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH );
345 virtual bool HasBBox()
const override {
return false; }
351 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
356 virtual bool IsInfo()
const override {
return true; }
361 virtual bool Inside(
const wxPoint& point )
const;
365 virtual void Move( wxPoint
delta );
368 virtual void UpdateReference();
372 wxPoint GetPosition()
const;
376 wxSize GetSize()
const;
402 mpInfoLegend( wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH );
411 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
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
447#define mpX_HOURS 0x02
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
488 virtual double GetY(
double x )
const = 0;
494 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
499 DECLARE_DYNAMIC_CLASS(
mpFX )
520 virtual double GetX(
double y )
const = 0;
526 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
531 DECLARE_DYNAMIC_CLASS(
mpFY )
567 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
573 double s2x(
double plotCoordX )
const;
574 double s2y(
double plotCoordY )
const;
576 double x2s(
double x )
const;
577 double y2s(
double y )
const;
591 void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
593 DECLARE_DYNAMIC_CLASS(
mpFXY )
619 bool HasBBox()
const override {
return false; }
632 void SetTicks(
bool enable ) { m_ticks = enable; };
655 m_minV = std::min( minV, m_minV );
656 m_maxV = std::max( maxV, m_maxV );
659 if( m_minV == m_maxV )
661 m_minV = m_minV - 1.0;
662 m_maxV = m_maxV + 1.0;
678 return m_absVisibleMaxV;
695 else if( !m_tickValues.empty() )
697 *minV = m_tickValues.front();
698 *maxV = m_tickValues.back();
709 TICK_LABEL(
double pos_ = 0.0,
const wxString& label_ = wxT(
"" ) ) :
722 void updateTickLabels( wxDC& dc,
mpWindow& w );
723 void computeLabelExtents( wxDC& dc,
mpWindow& w );
764 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
766 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
785 virtual double TransformToPlot(
double x )
const override;
786 virtual double TransformFromPlot(
double xplot )
const override;
789 virtual void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
806 bool ticks =
true,
unsigned int type =
mpX_NORMAL );
808 virtual double TransformToPlot(
double x )
const override;
809 virtual double TransformFromPlot(
double xplot )
const override;
812 void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
840 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
846 virtual bool HasBBox()
const override {
return false; }
848 virtual double TransformToPlot(
double x )
const override;
849 virtual double TransformFromPlot(
double xplot )
const override;
854 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
855 virtual void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
857 void computeSlaveTicks(
mpWindow& w );
874#define mpMOUSEMODE_DRAG 0
876#define mpMOUSEMODE_ZOOMBOX 1
941 mpWindow( wxWindow* parent, wxWindowID
id );
957 bool AddLayer(
mpLayer* layer,
bool refreshDisplay =
true );
969 bool DelLayer(
mpLayer* layer,
bool alsoDeleteObject =
false,
bool refreshDisplay =
true );
977 void DelAllLayers(
bool alsoDeleteObject,
bool refreshDisplay =
true );
985 mpLayer* GetLayer(
int position )
const;
991 const mpLayer* GetLayerByName(
const wxString&
name )
const;
994 return const_cast<mpLayer*
>(
static_cast<const mpWindow*
>( this )->GetLayerByName(
name ) );
1042 void SetScaleX(
double scaleX );
1058 void SetPosX(
double posX ) { m_posX = posX; UpdateAll(); }
1063 void SetPosY(
double posY ) { m_posY = posY; UpdateAll(); }
1069 void SetPos(
double posX,
double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
1076 void SetScr(
int scrX,
int scrY ) { m_scrX = scrX; m_scrY = scrY; }
1080 inline double p2x( wxCoord pixelCoordX ) {
return m_posX + pixelCoordX / m_scaleX; }
1084 inline double p2y( wxCoord pixelCoordY ) {
return m_posY - pixelCoordY / m_scaleY; }
1088 inline wxCoord
x2p(
double x ) {
return (wxCoord) ( (x - m_posX) * m_scaleX ); }
1092 inline wxCoord
y2p(
double y ) {
return (wxCoord) ( (m_posY - y) * m_scaleY ); }
1110 void Fit()
override;
1118 void Fit(
double xMin,
double xMax,
double yMin,
double yMax,
1119 const wxCoord* printSizeX =
nullptr,
const wxCoord* printSizeY =
nullptr,
1120 wxOrientation directions = wxBOTH );
1126 void ZoomIn(
const wxPoint& centerPoint = wxDefaultPosition );
1127 void ZoomIn(
const wxPoint& centerPoint,
double zoomFactor, wxOrientation directions = wxBOTH );
1133 void ZoomOut(
const wxPoint& centerPoint = wxDefaultPosition );
1134 void ZoomOut(
const wxPoint& centerPoint,
double zoomFactor,
1135 wxOrientation directions = wxBOTH );
1139 void ZoomRect( wxPoint p0, wxPoint p1 );
1177 void GetBoundingBox(
double* bbox )
const;
1184 bool SaveScreenshot( wxImage& aImage,
1185 wxSize aImageSize = wxDefaultSize,
bool aFit =
false );
1199 void SetMargins(
int top,
int right,
int bottom,
int left );
1227 void SetLayerVisible(
const wxString&
name,
bool viewable );
1232 bool IsLayerVisible(
const wxString&
name )
const;
1237 void SetLayerVisible(
const unsigned int position,
bool viewable );
1242 bool IsLayerVisible(
unsigned int position )
const;
1248 void SetColourTheme(
const wxColour& bgColour,
const wxColour& drawColour,
1249 const wxColour& axesColour );
1258 m_enableLimitedView = aEnable;
1261 void LockY(
bool aLock ) { m_yLocked = aLock; }
1270 void AdjustLimitedView( wxOrientation directions = wxBOTH );
1272 void OnFit( wxCommandEvent& event );
1273 void OnCenter( wxCommandEvent& event );
1276 static MouseWheelActionSet defaultMouseWheelActions();
1278 void pushZoomUndo(
const std::array<double, 4>& aZoom );
1280 void OnPaint( wxPaintEvent& event );
1281 void OnSize( wxSizeEvent& event );
1283 void OnShowPopupMenu( wxMouseEvent& event );
1284 void OnMouseMiddleDown( wxMouseEvent& event );
1287 void onZoomIn( wxCommandEvent& event );
1288 void onZoomOut( wxCommandEvent& event );
1289 void onZoomUndo( wxCommandEvent& event );
1290 void onZoomRedo( wxCommandEvent& event );
1291 void onMouseWheel( wxMouseEvent& event );
1292 void onMagnify( wxMouseEvent& event );
1293 void onMouseMove( wxMouseEvent& event );
1294 void onMouseLeftDown( wxMouseEvent& event );
1295 void onMouseLeftRelease( wxMouseEvent& event );
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;
1302 void PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction action );
1307 virtual bool UpdateBBox();
1312 virtual bool SetXView(
double pos,
double desiredMax,
double desiredMin );
1317 virtual bool SetYView(
double pos,
double desiredMax,
double desiredMin );
1372 DECLARE_EVENT_TABLE()
1377 template <
typename... Ts>
1380 void initializeGraphicsContext();
1420 virtual void SetData(
const std::vector<double>& xs,
const std::vector<double>& ys );
1443 void Rewind()
override;
1450 bool GetNextXY(
double& x,
double& y )
override;
1452 size_t GetCount()
const override;
1457 double GetMinX()
const override {
return m_minX; }
1461 double GetMinY()
const override {
return m_minY; }
1465 double GetMaxX()
const override {
return m_maxX; }
1469 double GetMaxY()
const override {
return m_maxY; }
A class providing graphs functionality for a 2D plot (either continuous or a set of points),...
double GetMaxY() const override
Returns the actual maximum Y data (loaded in SetData).
double GetMinY() const override
Returns the actual minimum Y data (loaded in SetData).
double GetMinX() const override
Returns the actual minimum X data (loaded in SetData).
std::vector< double > m_xs
The internal copy of the set of data to draw.
double GetMaxX() const override
Returns the actual maximum X data (loaded in SetData).
size_t m_index
The internal counter for the "GetNextXY" interface.
Abstract base class providing plot and labeling functionality for a locus plot F:N->X,...
virtual void Rewind()=0
Rewind value enumeration with mpFXY::GetNextXY.
virtual size_t GetCount() const =0
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.
virtual double GetY(double x) const =0
Get function value for argument.
Abstract base class providing plot and labeling functionality for functions F:Y->X.
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...
virtual bool HasBBox() const override
mpInfoLayer has not bounding box.
virtual bool IsInfo() const override
Specifies that this is an Info box layer.
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
const wxString & GetDisplayName() const
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,...
void SetFont(const wxFont &font)
Set layer font.
bool IsVisible() const
Checks whether the layer is visible or not.
const wxString & GetName() const
Get layer name.
virtual double GetMinY() const
Get inclusive bottom border of bounding box.
bool GetContinuity() const
Gets the 'continuity' property of the layer.
virtual bool IsInfo() const
Check whether the layer is an info box.
void SetContinuity(bool continuity)
Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points...
void ShowName(bool show)
Shows or hides the text label with the name of the layer (default is visible).
virtual void SetName(const wxString &name)
Set layer name.
const wxFont & GetFont() const
Get font set for this layer.
const wxPen & GetPen() const
Get pen set for this layer.
void SetVisible(bool show)
Sets layer visibility.
void SetPen(const wxPen &pen)
Set layer pen.
void SetBrush(const wxBrush &brush)
Set layer brush.
virtual double GetMaxX() const
Get inclusive right border of bounding box.
const wxBrush & GetBrush() const
Get brush set for this layer.
virtual double GetMinX() const
Get inclusive left border of bounding box.
virtual double GetMaxY() const
Get inclusive top border of bounding box.
virtual bool HasBBox() const
Check whether this layer has a bounding box.
Plot layer implementing a x-scale ruler.
void SetAxisMinMax(bool lock, double minV, double maxV)
void SetNameAlign(int align)
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
double AbsMaxValue() const
void GetDataRange(double &minV, double &maxV) const
std::vector< double > m_tickValues
double AbsVisibleMaxValue() const
bool HasBBox() const override
Check whether this layer has a bounding box.
void SetAlign(int align)
Set X axis alignment.
void SetTicks(bool enable)
Set X axis ticks or grid.
virtual double TransformToPlot(double x) const
virtual void ResetDataRange()
virtual void formatLabels()
virtual bool IsHorizontal() const =0
bool GetTicks() const
Get X axis ticks or grid.
virtual void ExtendDataRange(double minV, double maxV)
std::vector< TICK_LABEL > m_tickLabels
bool GetAxisMinMax(double *minV, double *maxV)
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV)
virtual double TransformFromPlot(double xplot) const
virtual bool IsHorizontal() const override
Plot layer implementing a y-scale ruler.
virtual bool IsHorizontal() const override
void SetMasterScale(mpScaleY *masterScale)
virtual bool HasBBox() const override
Check whether this layer has a bounding box.
Canvas for plotting mpLayer implementations.
mpInfoLayer * m_movingInfoLayer
int RedoZoomStackSize() const
int GetMarginLeft() const
bool m_enableMouseNavigation
void EnableMousePanZoom(bool enabled)
Enable/disable the feature of pan/zoom with the mouse (default=enabled)
void SetMarginLeft(int left)
Set the left margin.
const wxColour & GetAxesColour()
Get axes draw colour.
MouseWheelActionSet m_mouseWheelActions
int GetScrX() const
Get current view's X dimension in device context units.
int GetScrY() const
Get current view's Y dimension in device context units.
void SetMouseWheelActions(const MouseWheelActionSet &s)
Set the pan/zoom actions corresponding to mousewheel/trackpad events.
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
void SetMarginRight(int right)
Set the right margin.
void LimitView(bool aEnable)
Enable limiting of zooming & panning to the area used by the plots.
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
MouseWheelAction
Enumerates the possible mouse wheel actions that can be performed on the plot.
double m_leftRightPlotGapFactor
void SetMarginTop(int top)
Set the top margin.
std::stack< std::array< double, 4 > > m_redoZoomStack
void SetPosX(double posX)
Set current view's X position and refresh display.
double GetDesiredYmax() const
Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exact...
void SetMarginBottom(int bottom)
Set the bottom margin.
void SetPosY(double posY)
Set current view's Y position and refresh display.
void SetScaleY(double scaleY)
Set current view's Y scale and refresh display.
double GetDesiredYmin() const
Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not ex...
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
double GetDesiredXmax() const
Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exa...
double m_topBottomPlotGapFactor
wxMenu * GetPopupMenu()
Get reference to context menu of the plot canvas.
double GetDesiredXmin() const
Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exac...
std::stack< std::array< double, 4 > > m_undoZoomStack
int GetMarginRight() const
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
int GetMarginBottom() const
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
mpLayer * GetLayerByName(const wxString &name)
int UndoZoomStackSize() const
bool m_enableDoubleBuffer
unsigned int CountAllLayers() const
Counts the number of plot layers, whether or not they have a bounding box.
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
double GetScaleY() const
Get current view's Y scale.
double GetScaleX() const
Get current view's X scale.
double GetPosY() const
Get current view's Y position.
double GetPosX() const
Get current view's X position.
class WXDLLIMPEXP_MATHPLOT mpPrintout
#define mpALIGN_RIGHT
Aligns label to the right.
enum __mp_Layer_Type mpLayerType
std::deque< mpLayer * > wxLayerList
Define the type for the list of layers inside mpWindow.
#define mpALIGN_CENTER
Aligns label to the center.
#define mpALIGN_TOP
Aligns label to the top.
#define WXDLLIMPEXP_MATHPLOT
wxMathPlot is a framework for mathematical graph plotting in wxWindows.
#define mpX_NORMAL
Set label for X axis in normal mode.
#define mpALIGN_NE
Aligns label to north-east.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
TICK_LABEL(double pos_=0.0, const wxString &label_=wxT(""))
Contains the set of modified mouse wheel actions that can be performed on the plot.
MouseWheelAction horizontal
MouseWheelAction verticalWithShift
MouseWheelAction verticalWithCtrl
MouseWheelAction verticalWithAlt
MouseWheelAction verticalUnmodified