13#ifndef _MP_MATHPLOT_H_
14#define _MP_MATHPLOT_H_
61#ifdef mathplot_EXPORTS
62#define WXDLLIMPEXP_MATHPLOT WXEXPORT
63#define WXDLLIMPEXP_DATA_MATHPLOT( type ) WXEXPORT type
65#define WXDLLIMPEXP_MATHPLOT
66#define WXDLLIMPEXP_DATA_MATHPLOT( type ) type
73#include <wx/scrolwin.h>
75#include <wx/dynarray.h>
77#include <wx/dcmemory.h>
91#define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
98#define X_BORDER_SEPARATION 40
99#define Y_BORDER_SEPARATION 60
172 virtual bool IsInfo()
const {
return false; };
177 virtual double GetMinX()
const {
return -1.0; }
182 virtual double GetMaxX()
const {
return 1.0; }
187 virtual double GetMinY()
const {
return -1.0; }
192 virtual double GetMaxY()
const {
return 1.0; }
240 const wxString&
GetName()
const {
return m_name; }
244 return m_displayName.IsEmpty() ? m_name : m_displayName;
250 const wxFont&
GetFont()
const {
return m_font; }
255 const wxPen&
GetPen()
const {
return m_pen; }
279 void SetFont(
const wxFont& font ) { m_font = font; }
284 void SetPen(
const wxPen& pen ) { m_pen = pen; }
300 const wxBrush&
GetBrush()
const {
return m_brush; };
304 void SetBrush(
const wxBrush& brush ) { m_brush = brush; };
318 DECLARE_DYNAMIC_CLASS(
mpLayer )
339 mpInfoLayer( wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH );
346 virtual bool HasBBox()
const override {
return false; }
352 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
357 virtual bool IsInfo()
const override {
return true; }
362 virtual bool Inside(
const wxPoint& point )
const;
366 virtual void Move( wxPoint
delta );
369 virtual void UpdateReference();
373 wxPoint GetPosition()
const;
377 wxSize GetSize()
const;
403 mpInfoLegend( wxRect rect,
const wxBrush* brush = wxTRANSPARENT_BRUSH );
412 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
426#define mpALIGNMASK 0x03
428#define mpALIGN_RIGHT 0x00
430#define mpALIGN_CENTER 0x01
432#define mpALIGN_LEFT 0x02
434#define mpALIGN_TOP mpALIGN_RIGHT
436#define mpALIGN_BOTTOM mpALIGN_LEFT
438#define mpALIGN_BORDER_BOTTOM 0x04
440#define mpALIGN_BORDER_TOP 0x05
442#define mpALIGN_FAR_RIGHT 0x06
444#define mpX_NORMAL 0x00
448#define mpX_HOURS 0x02
452#define mpX_DATETIME 0x04
454#define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
456#define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
458#define mpALIGN_NE 0x00
460#define mpALIGN_NW 0x01
462#define mpALIGN_SW 0x02
464#define mpALIGN_SE 0x03
489 virtual double GetY(
double x )
const = 0;
495 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
500 DECLARE_DYNAMIC_CLASS(
mpFX )
521 virtual double GetX(
double y )
const = 0;
527 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
532 DECLARE_DYNAMIC_CLASS(
mpFY )
568 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
574 double s2x(
double plotCoordX )
const;
575 double s2y(
double plotCoordY )
const;
577 double x2s(
double x )
const;
578 double y2s(
double y )
const;
592 void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
594 DECLARE_DYNAMIC_CLASS(
mpFXY )
620 bool HasBBox()
const override {
return false; }
633 void SetTicks(
bool enable ) { m_ticks = enable; };
656 m_minV = std::min( minV, m_minV );
657 m_maxV = std::max( maxV, m_maxV );
660 if( m_minV == m_maxV )
662 m_minV = m_minV - 1.0;
663 m_maxV = m_maxV + 1.0;
679 return m_absVisibleMaxV;
696 else if( !m_tickValues.empty() )
698 *minV = m_tickValues.front();
699 *maxV = m_tickValues.back();
710 TICK_LABEL(
double pos_ = 0.0,
const wxString& label_ = wxT(
"" ) ) :
723 void updateTickLabels( wxDC& dc,
mpWindow& w );
724 void computeLabelExtents( wxDC& dc,
mpWindow& w );
765 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
767 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
786 virtual double TransformToPlot(
double x )
const override;
787 virtual double TransformFromPlot(
double xplot )
const override;
790 virtual void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
807 bool ticks =
true,
unsigned int type =
mpX_NORMAL );
809 virtual double TransformToPlot(
double x )
const override;
810 virtual double TransformFromPlot(
double xplot )
const override;
813 void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
841 virtual void Plot( wxDC& dc,
mpWindow& w )
override;
847 virtual bool HasBBox()
const override {
return false; }
849 virtual double TransformToPlot(
double x )
const override;
850 virtual double TransformFromPlot(
double xplot )
const override;
855 virtual void getVisibleDataRange(
mpWindow& w,
double& minV,
double& maxV )
override;
856 virtual void recalculateTicks( wxDC& dc,
mpWindow& w )
override;
858 void computeSlaveTicks(
mpWindow& w );
875#define mpMOUSEMODE_DRAG 0
877#define mpMOUSEMODE_ZOOMBOX 1
910 mpWindow( wxWindow* parent, wxWindowID
id );
926 bool AddLayer(
mpLayer* layer,
bool refreshDisplay =
true );
938 bool DelLayer(
mpLayer* layer,
bool alsoDeleteObject =
false,
bool refreshDisplay =
true );
946 void DelAllLayers(
bool alsoDeleteObject,
bool refreshDisplay =
true );
954 mpLayer* GetLayer(
int position )
const;
960 const mpLayer* GetLayerByName(
const wxString&
name )
const;
963 return const_cast<mpLayer*
>(
static_cast<const mpWindow*
>( this )->GetLayerByName(
name ) );
1011 void SetScaleX(
double scaleX );
1027 void SetPosX(
double posX ) { m_posX = posX; UpdateAll(); }
1032 void SetPosY(
double posY ) { m_posY = posY; UpdateAll(); }
1038 void SetPos(
double posX,
double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
1045 void SetScr(
int scrX,
int scrY ) { m_scrX = scrX; m_scrY = scrY; }
1049 inline double p2x( wxCoord pixelCoordX ) {
return m_posX + pixelCoordX / m_scaleX; }
1053 inline double p2y( wxCoord pixelCoordY ) {
return m_posY - pixelCoordY / m_scaleY; }
1057 inline wxCoord
x2p(
double x ) {
return (wxCoord) ( (x - m_posX) * m_scaleX ); }
1061 inline wxCoord
y2p(
double y ) {
return (wxCoord) ( (m_posY - y) * m_scaleY ); }
1080 void Fit()
override;
1088 void Fit(
double xMin,
double xMax,
double yMin,
double yMax,
1089 const wxCoord* printSizeX =
nullptr,
const wxCoord* printSizeY =
nullptr );
1095 void ZoomIn(
const wxPoint& centerPoint = wxDefaultPosition );
1096 void ZoomIn(
const wxPoint& centerPoint,
double zoomFactor );
1102 void ZoomOut(
const wxPoint& centerPoint = wxDefaultPosition );
1103 void ZoomOut(
const wxPoint& centerPoint,
double zoomFactor );
1107 void ZoomRect( wxPoint p0, wxPoint p1 );
1145 void GetBoundingBox(
double* bbox )
const;
1152 bool SaveScreenshot(
const wxString& filename, wxBitmapType type = wxBITMAP_TYPE_BMP,
1153 wxSize imageSize = wxDefaultSize,
bool fit =
false );
1167 void SetMargins(
int top,
int right,
int bottom,
int left );
1195 void SetLayerVisible(
const wxString&
name,
bool viewable );
1200 bool IsLayerVisible(
const wxString&
name )
const;
1205 void SetLayerVisible(
const unsigned int position,
bool viewable );
1210 bool IsLayerVisible(
unsigned int position )
const;
1216 void SetColourTheme(
const wxColour& bgColour,
const wxColour& drawColour,
1217 const wxColour& axesColour );
1226 m_enableLimitedView = aEnable;
1229 void LockY(
bool aLock ) { m_yLocked = aLock; }
1232 void AdjustLimitedView();
1235 void OnPaint( wxPaintEvent& event );
1236 void OnSize( wxSizeEvent& event );
1238 void OnShowPopupMenu( wxMouseEvent& event );
1239 void OnMouseMiddleDown( wxMouseEvent& event );
1242 void OnCenter( wxCommandEvent& event );
1243 void OnFit( wxCommandEvent& event );
1244 void OnZoomIn( wxCommandEvent& event );
1245 void OnZoomOut( wxCommandEvent& event );
1246 void OnMouseWheel( wxMouseEvent& event );
1247 void OnMagnify( wxMouseEvent& event );
1248 void OnMouseMove( wxMouseEvent& event );
1249 void OnMouseLeftDown( wxMouseEvent& event );
1250 void OnMouseLeftRelease( wxMouseEvent& event );
1254 return !( m_enableLimitedView
1255 && (desiredMax > m_maxX - m_marginRight / m_scaleX
1256 || desiredMin < m_minX - m_marginLeft / m_scaleX) );
1261 return !( m_enableLimitedView
1262 && (desiredMax > m_maxY + m_marginTop / m_scaleY
1263 || desiredMin < m_minY - m_marginBottom / m_scaleY) );
1269 virtual bool UpdateBBox();
1274 virtual bool SetXView(
double pos,
double desiredMax,
double desiredMin );
1279 virtual bool SetYView(
double pos,
double desiredMax,
double desiredMin );
1323 DECLARE_EVENT_TABLE()
1363 virtual void SetData(
const std::vector<double>& xs,
const std::vector<double>& ys );
1386 void Rewind()
override;
1393 bool GetNextXY(
double& x,
double& y )
override;
1395 size_t GetCount()
const override;
1400 double GetMinX()
const override {
return m_minX; }
1404 double GetMinY()
const override {
return m_minY; }
1408 double GetMaxX()
const override {
return m_maxX; }
1412 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 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.
bool m_enableMouseWheelPan
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.
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)
Limit zooming & panning to the area used by the plots.
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
void SetMarginTop(int top)
Set the top margin.
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...
bool CheckYLimits(double &desiredMax, double &desiredMin) const
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...
bool CheckXLimits(double &desiredMax, double &desiredMin) const
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...
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)
bool m_enableDoubleBuffer
void EnableMouseWheelPan(bool enabled)
Enable/disable trackpad friendly panning (2-axis scroll wheel)
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
#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(""))