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 )
569 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
575 double s2x(
double plotCoordX )
const;
576 double s2y(
double plotCoordY )
const;
578 double x2s(
double x )
const;
579 double y2s(
double y )
const;
593 void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
595 DECLARE_DYNAMIC_CLASS(
mpFXY )
621 bool HasBBox()
const override {
return false; }
634 void SetTicks(
bool enable ) { m_ticks = enable; };
657 m_minV = std::min( minV, m_minV );
658 m_maxV = std::max( maxV, m_maxV );
661 if( m_minV == m_maxV )
663 m_minV = m_minV - 1.0;
664 m_maxV = m_maxV + 1.0;
680 return m_absVisibleMaxV;
697 else if( !m_tickValues.empty() )
699 *minV = m_tickValues.front();
700 *maxV = m_tickValues.back();
711 TICK_LABEL(
double pos_ = 0.0,
const wxString& label_ = wxT(
"" ) ) :
724 void updateTickLabels( wxDC& dc,
mpWindow& w );
725 void computeLabelExtents( wxDC& dc,
mpWindow& w );
766 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
768 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
787 virtual double TransformToPlot(
double x )
const override;
788 virtual double TransformFromPlot(
double xplot )
const override;
791 virtual void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
808 bool ticks =
true,
unsigned int type =
mpX_NORMAL );
810 virtual double TransformToPlot(
double x )
const override;
811 virtual double TransformFromPlot(
double xplot )
const override;
814 void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
842 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
848 virtual bool HasBBox()
const override {
return false; }
850 virtual double TransformToPlot(
double x )
const override;
851 virtual double TransformFromPlot(
double xplot )
const override;
856 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
857 virtual void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
859 void computeSlaveTicks(
mpWindow& w );
876#define mpMOUSEMODE_DRAG 0
878#define mpMOUSEMODE_ZOOMBOX 1
943 mpWindow( wxWindow* parent, wxWindowID
id );
959 bool AddLayer(
mpLayer* layer,
bool refreshDisplay =
true );
971 bool DelLayer(
mpLayer* layer,
bool alsoDeleteObject =
false,
bool refreshDisplay =
true );
979 void DelAllLayers(
bool alsoDeleteObject,
bool refreshDisplay =
true );
987 mpLayer* GetLayer(
int position )
const;
993 const mpLayer* GetLayerByName(
const wxString&
name )
const;
996 return const_cast<mpLayer*
>(
static_cast<const mpWindow*
>( this )->GetLayerByName(
name ) );
1044 void SetScaleX(
double scaleX );
1060 void SetPosX(
double posX ) { m_posX = posX; UpdateAll(); }
1065 void SetPosY(
double posY ) { m_posY = posY; UpdateAll(); }
1071 void SetPos(
double posX,
double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
1078 void SetScr(
int scrX,
int scrY ) { m_scrX = scrX; m_scrY = scrY; }
1082 inline double p2x( wxCoord pixelCoordX ) {
return m_posX + pixelCoordX / m_scaleX; }
1086 inline double p2y( wxCoord pixelCoordY ) {
return m_posY - pixelCoordY / m_scaleY; }
1090 inline wxCoord
x2p(
double x ) {
return (wxCoord) ( (x - m_posX) * m_scaleX ); }
1094 inline wxCoord
y2p(
double y ) {
return (wxCoord) ( (m_posY - y) * m_scaleY ); }
1112 void Fit()
override;
1120 void Fit(
double xMin,
double xMax,
double yMin,
double yMax,
1121 const wxCoord* printSizeX =
nullptr,
const wxCoord* printSizeY =
nullptr,
1122 wxOrientation directions = wxBOTH );
1128 void ZoomIn(
const wxPoint& centerPoint = wxDefaultPosition );
1129 void ZoomIn(
const wxPoint& centerPoint,
double zoomFactor, wxOrientation directions = wxBOTH );
1135 void ZoomOut(
const wxPoint& centerPoint = wxDefaultPosition );
1136 void ZoomOut(
const wxPoint& centerPoint,
double zoomFactor,
1137 wxOrientation directions = wxBOTH );
1141 void ZoomRect( wxPoint p0, wxPoint p1 );
1179 void GetBoundingBox(
double* bbox )
const;
1186 bool SaveScreenshot( wxImage& aImage,
1187 wxSize aImageSize = wxDefaultSize,
bool aFit =
false );
1201 void SetMargins(
int top,
int right,
int bottom,
int left );
1229 void SetLayerVisible(
const wxString&
name,
bool viewable );
1234 bool IsLayerVisible(
const wxString&
name )
const;
1239 void SetLayerVisible(
const unsigned int position,
bool viewable );
1244 bool IsLayerVisible(
unsigned int position )
const;
1250 void SetColourTheme(
const wxColour& bgColour,
const wxColour& drawColour,
1251 const wxColour& axesColour );
1260 m_enableLimitedView = aEnable;
1263 void LockY(
bool aLock ) { m_yLocked = aLock; }
1272 void AdjustLimitedView( wxOrientation directions = wxBOTH );
1274 void OnFit( wxCommandEvent& event );
1275 void OnCenter( wxCommandEvent& event );
1278 static MouseWheelActionSet defaultMouseWheelActions();
1280 void pushZoomUndo(
const std::array<double, 4>& aZoom );
1282 void OnPaint( wxPaintEvent& event );
1283 void OnSize( wxSizeEvent& event );
1285 void OnShowPopupMenu( wxMouseEvent& event );
1286 void OnMouseMiddleDown( wxMouseEvent& event );
1289 void onZoomIn( wxCommandEvent& event );
1290 void onZoomOut( wxCommandEvent& event );
1291 void onZoomUndo( wxCommandEvent& event );
1292 void onZoomRedo( wxCommandEvent& event );
1293 void onMouseWheel( wxMouseEvent& event );
1294 void onMagnify( wxMouseEvent& event );
1295 void onMouseMove( wxMouseEvent& event );
1296 void onMouseLeftDown( wxMouseEvent& event );
1297 void onMouseLeftRelease( wxMouseEvent& event );
1299 void DoZoom(
const wxPoint& centerPoint,
double zoomFactor, wxOrientation directions );
1300 void RecomputeDesiredX(
double& min,
double& max );
1301 void RecomputeDesiredY(
double& min,
double& max );
1302 wxOrientation ViewNeedsRefitting( wxOrientation directions )
const;
1304 void PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction action );
1309 virtual bool UpdateBBox();
1314 virtual bool SetXView(
double pos,
double desiredMax,
double desiredMin );
1319 virtual bool SetYView(
double pos,
double desiredMax,
double desiredMin );
1374 DECLARE_EVENT_TABLE()
1379 template <
typename... Ts>
1382 void initializeGraphicsContext();
1422 virtual void SetData(
const std::vector<double>& xs,
const std::vector<double>& ys );
1443 int m_sweepCount = 1;
1444 size_t m_sweepSize = std::numeric_limits<size_t>::max();
1449 void Rewind()
override;
1450 void SetSweepWindow(
int aSweepIdx )
override;
1457 bool GetNextXY(
double& x,
double& y )
override;
1459 size_t GetCount()
const override {
return m_xs.size(); }
1465 double GetMinX()
const override {
return m_minX; }
1469 double GetMinY()
const override {
return m_minY; }
1473 double GetMaxX()
const override {
return m_maxX; }
1477 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).
void SetSweepSize(size_t aSweepSize)
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).
void SetSweepCount(int aSweepCount)
size_t GetCount() const override
int GetSweepCount() const override
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 void SetSweepWindow(int aSweepIdx)
virtual size_t GetCount() const =0
virtual int GetSweepCount() const
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)
@ NONE
No connection to this item.
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