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; }
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 );
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;
499 DECLARE_DYNAMIC_CLASS(
mpFX )
520 virtual double GetX(
double y )
const = 0;
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;
595 DECLARE_DYNAMIC_CLASS(
mpFXY )
621 bool HasBBox()
const override {
return false; }
711 TICK_LABEL(
double pos_ = 0.0,
const wxString& label_ = wxT(
"" ) ) :
766 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
768 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
808 bool ticks =
true,
unsigned int type =
mpX_NORMAL );
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 );
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 );
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 );
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>
1422 virtual void SetData(
const std::vector<double>& xs,
const std::vector<double>& ys );
1457 bool GetNextXY(
double& x,
double& y )
override;
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 SetSweepWindow(int aSweepIdx) override
void SetSweepSize(size_t aSweepSize)
double GetMinY() const override
Returns the actual minimum Y data (loaded in SetData).
bool GetNextXY(double &x, double &y) override
Get locus value for next N.
double GetMinX() const override
Returns the actual minimum X data (loaded in SetData).
mpFXYVector(const wxString &name=wxEmptyString, int flags=mpALIGN_NE)
std::vector< double > m_ys
double m_minX
Loaded at SetData.
std::vector< double > m_xs
The internal copy of the set of data to draw.
void Rewind() override
Rewind value enumeration with mpFXY::GetNextXY.
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
mpFXY(const wxString &name=wxEmptyString, int flags=mpALIGN_NE)
void UpdateViewBoundary(wxCoord xnew, wxCoord ynew)
Update label positioning data.
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.
mpFX(const wxString &name=wxEmptyString, int flags=mpALIGN_RIGHT)
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
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.
mpFY(const wxString &name=wxEmptyString, int flags=mpALIGN_TOP)
virtual void Plot(wxDC &dc, mpWindow &w) override
Layer plot handler.
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.
mpInfoLayer()
Default constructor.
virtual bool IsInfo() const override
Specifies that this is an Info box layer.
mpInfoLegend()
Default constructor.
virtual void Plot(wxDC &dc, mpWindow &w) override
Plot method.
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
void computeLabelExtents(wxDC &dc, mpWindow &w)
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)
void updateTickLabels(wxDC &dc, mpWindow &w)
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV)
virtual double TransformFromPlot(double xplot) const
mpScaleXBase(const wxString &name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
virtual bool IsHorizontal() const override
mpScaleXLog(const wxString &name=wxT("log(X)"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
virtual double TransformFromPlot(double xplot) const override
virtual double TransformToPlot(double x) const override
void recalculateTicks(wxDC &dc, mpWindow &w) override
virtual double TransformToPlot(double x) const override
virtual double TransformFromPlot(double xplot) const override
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
mpScaleX(const wxString &name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
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.
mpScaleY(const wxString &name=wxT("Y"), int flags=mpALIGN_CENTER, bool ticks=true)
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.
void SetMargins(int top, int right, int bottom, int left)
Set window margins, creating a blank area where some kinds of layers cannot draw.
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 initializeGraphicsContext()
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...
void UpdateAll()
Refresh display.
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
double m_desiredXmin
These are updated in Fit, ZoomIn, ZoomOut, ZoomRect, SetXView, SetYView and may be different from the...
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 mpFY
class WXDLLIMPEXP_MATHPLOT mpWindow
class WXDLLIMPEXP_MATHPLOT mpPrintout
class WXDLLIMPEXP_MATHPLOT mpFXYVector
#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.
class WXDLLIMPEXP_MATHPLOT mpFXY
#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.
class WXDLLIMPEXP_MATHPLOT mpLayer
class WXDLLIMPEXP_MATHPLOT mpFX
class WXDLLIMPEXP_MATHPLOT mpScaleX
class WXDLLIMPEXP_MATHPLOT mpScaleY
#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