KiCad PCB EDA Suite
mpScaleY Class Reference

Plot layer implementing a y-scale ruler. More...

#include <mathplot.h>

Inheritance diagram for mpScaleY:
mpScaleBase mpLayer CURRENT_SCALE GAIN_SCALE PHASE_SCALE VOLTAGE_SCALE_Y

Public Member Functions

 mpScaleY (wxString name=wxT("Y"), int flags=mpALIGN_CENTER, bool ticks=true)
 
virtual bool IsHorizontal () override
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Layer plot handler. More...
 
virtual bool HasBBox () override
 Check whether this layer has a bounding box. More...
 
void SetAlign (int align)
 Set Y axis alignment. More...
 
void SetTicks (bool ticks)
 Set Y axis ticks or grid. More...
 
bool GetTicks ()
 Get Y axis ticks or grid. More...
 
virtual double TransformToPlot (double x) override
 
virtual double TransformFromPlot (double xplot) override
 
void SetMasterScale (mpScaleY *masterScale)
 
void SetNameAlign (int align)
 
void SetDataRange (double minV, double maxV)
 
void GetDataRange (double &minV, double &maxV)
 
void ExtendDataRange (double minV, double maxV)
 
void ResetDataRange ()
 
double AbsMaxValue () const
 
double AbsVisibleMaxValue () const
 
std::vector< TickLabel > & TickLabels ()
 
virtual bool IsInfo ()
 Check whether the layer is an info box. More...
 
virtual double GetMinX ()
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX ()
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY ()
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY ()
 Get inclusive top border of bounding box. More...
 
const wxString & GetName () const
 Get layer name. More...
 
const wxFont & GetFont () const
 Get font set for this layer. More...
 
const wxPen & GetPen () const
 Get pen set for this layer. More...
 
void SetContinuity (bool continuity)
 Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points). More...
 
bool GetContinuity () const
 Gets the 'continuity' property of the layer. More...
 
void ShowName (bool show)
 Shows or hides the text label with the name of the layer (default is visible). More...
 
void SetName (wxString name)
 Set layer name. More...
 
void SetFont (wxFont &font)
 Set layer font. More...
 
void SetPen (wxPen pen)
 Set layer pen. More...
 
void SetDrawOutsideMargins (bool drawModeOutside)
 Set Draw mode: inside or outside margins. More...
 
bool GetDrawOutsideMargins ()
 Get Draw mode: inside or outside margins. More...
 
wxBitmap GetColourSquare (int side=16)
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType ()
 Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value. More...
 
bool IsVisible ()
 Checks whether the layer is visible or not. More...
 
void SetVisible (bool show)
 Sets layer visibility. More...
 
const wxBrush & GetBrush () const
 Get brush set for this layer. More...
 
void SetBrush (wxBrush brush)
 Set layer brush. More...
 

Protected Member Functions

virtual void getVisibleDataRange (mpWindow &w, double &minV, double &maxV) override
 
virtual void recalculateTicks (wxDC &dc, mpWindow &w) override
 
void computeLabelExtents (wxDC &dc, mpWindow &w)
 
void computeSlaveTicks (mpWindow &w)
 
void updateTickLabels (wxDC &dc, mpWindow &w)
 
int tickCount () const
 
virtual int labelCount () const
 
virtual const wxString formatLabel (double value, int nDigits)
 
virtual void formatLabels ()
 
virtual double getTickPos (int n)
 
virtual double getLabelPos (int n)
 
virtual const wxString getLabel (int n)
 

Protected Attributes

mpScaleYm_masterScale
 
int m_flags
 
bool m_ticks
 
std::vector< double > m_tickValues
 
std::vector< TickLabelm_tickLabels
 
double m_offset
 
double m_scale
 
double m_absVisibleMaxV
 
int m_nameFlags
 
double m_minV
 
double m_maxV
 
bool m_rangeSet
 
int m_maxLabelHeight
 
int m_maxLabelWidth
 
wxFont m_font
 
wxPen m_pen
 
wxBrush m_brush
 
wxString m_name
 
bool m_continuous
 
bool m_showName
 
bool m_drawOutsideMargins
 
mpLayerType m_type
 
bool m_visible
 

Detailed Description

Plot layer implementing a y-scale ruler.

If align is set to mpALIGN_CENTER, the ruler is fixed at X=0 in the coordinate system. If the align is set to mpALIGN_TOP or mpALIGN_BOTTOM, the axis is always drawn respectively at top or bottom of the window. A label is plotted at the top-right hand of the ruler. The scale numbering automatically adjusts to view and zoom factor.

Definition at line 934 of file mathplot.h.

Constructor & Destructor Documentation

mpScaleY::mpScaleY ( wxString  name = wxT("Y"),
int  flags = mpALIGN_CENTER,
bool  ticks = true 
)
Parameters
nameLabel to plot by the ruler
flagsSet position of the scale respect to the window.
ticksSelect ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid

Definition at line 1504 of file mathplot.cpp.

References mpALIGN_BORDER_LEFT, and mpLAYER_AXIS.

1505 {
1506  SetName( name );
1507  SetFont( (wxFont&) *wxSMALL_FONT );
1508  SetPen( (wxPen&) *wxGREY_PEN );
1509  m_flags = flags;
1510  m_ticks = ticks;
1511  m_type = mpLAYER_AXIS;
1512  m_masterScale = NULL;
1514 }
void SetName(wxString name)
Set layer name.
Definition: mathplot.h:266
void SetPen(wxPen pen)
Set layer pen.
Definition: mathplot.h:276
#define mpALIGN_BORDER_LEFT
Aligns Y axis to left border.
Definition: mathplot.h:500
void SetFont(wxFont &font)
Set layer font.
Definition: mathplot.h:271
int m_flags
Definition: mathplot.h:993
bool m_ticks
Definition: mathplot.h:994
mpLayerType m_type
Definition: mathplot.h:320
int m_nameFlags
Definition: mathplot.h:827
mpScaleY * m_masterScale
Definition: mathplot.h:989

Member Function Documentation

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 757 of file mathplot.h.

References abs, and max.

758  {
759  return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
760  }
double m_maxV
Definition: mathplot.h:829
#define abs(a)
Definition: auxiliary.h:84
double m_minV
Definition: mathplot.h:829
#define max(a, b)
Definition: auxiliary.h:86
double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 762 of file mathplot.h.

Referenced by formatSILabels().

763  {
764  return m_absVisibleMaxV;
765  }
double m_absVisibleMaxV
Definition: mathplot.h:825
void mpScaleY::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protected
void mpScaleY::computeSlaveTicks ( mpWindow w)
protected

Definition at line 1069 of file mathplot.cpp.

References getVisibleDataRange(), mpScaleBase::m_absVisibleMaxV, m_masterScale, mpScaleBase::m_maxV, mpScaleBase::m_minV, mpScaleBase::m_offset, mpScaleBase::m_scale, mpScaleBase::m_tickLabels, mpScaleBase::m_tickValues, max, TransformFromPlot(), and TransformToPlot().

Referenced by recalculateTicks().

1070 {
1071  if( m_masterScale->m_tickValues.size() == 0 )
1072  return;
1073 
1074  m_tickValues.clear();
1075  m_tickLabels.clear();
1076 
1077  // printf("NTicks %d\n", m_masterScale->m_tickValues.size());
1080 
1081  m_scale = 1.0 / ( m_maxV - m_minV );
1082  m_offset = -m_minV;
1083 
1084  double y_slave0 = p0 / m_scale;
1085  double y_slave1 = p1 / m_scale;
1086 
1087  double dy_slave = (y_slave1 - y_slave0);
1088  double exponent = floor( log10( dy_slave ) );
1089  double base = dy_slave / pow( 10.0, exponent );
1090 
1091  double dy_scaled = ceil( 2.0 * base ) / 2.0 * pow( 10.0, exponent );
1092 
1093  double minvv, maxvv;
1094 
1095  getVisibleDataRange( w, minvv, maxvv );
1096 
1097  minvv = floor( minvv / dy_scaled ) * dy_scaled;
1098 
1099  m_scale = 1.0 / ( m_maxV - m_minV );
1100  m_scale *= dy_slave / dy_scaled;
1101 
1102  m_offset = p0 / m_scale - minvv;
1103 
1104  m_tickValues.clear();
1105 
1106  double m;
1107 
1108  m_absVisibleMaxV = 0;
1109 
1110  for( unsigned int i = 0; i < m_masterScale->m_tickValues.size(); i++ )
1111  {
1113  m_tickValues.push_back( m );
1114  m_tickLabels.push_back( TickLabel( m ) );
1115  m_absVisibleMaxV = std::max( m_absVisibleMaxV, fabs( m ) );
1116  }
1117 }
double m_maxV
Definition: mathplot.h:829
virtual double TransformToPlot(double x) override
Definition: mathplot.cpp:3295
double m_offset
Definition: mathplot.h:824
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
double m_absVisibleMaxV
Definition: mathplot.h:825
double m_minV
Definition: mathplot.h:829
double m_scale
Definition: mathplot.h:824
#define max(a, b)
Definition: auxiliary.h:86
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1054
virtual double TransformFromPlot(double xplot) override
Definition: mathplot.cpp:3301
mpScaleY * m_masterScale
Definition: mathplot.h:989
std::vector< double > m_tickValues
Definition: mathplot.h:821
void mpScaleBase::ExtendDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 731 of file mathplot.h.

References max, and min.

Referenced by mpFXY::UpdateScales().

732  {
733  if( !m_rangeSet )
734  {
735  m_minV = minV;
736  m_maxV = maxV;
737  m_rangeSet = true;
738  }
739  else
740  {
741  m_minV = std::min( minV, m_minV );
742  m_maxV = std::max( maxV, m_maxV );
743  }
744 
745  if( m_minV == m_maxV )
746  {
747  m_minV = -1.0;
748  m_maxV = 1.0;
749  }
750  }
double m_maxV
Definition: mathplot.h:829
bool m_rangeSet
Definition: mathplot.h:830
double m_minV
Definition: mathplot.h:829
#define max(a, b)
Definition: auxiliary.h:86
#define min(a, b)
Definition: auxiliary.h:85
virtual const wxString mpScaleBase::formatLabel ( double  value,
int  nDigits 
)
inlineprotectedvirtualinherited

Definition at line 803 of file mathplot.h.

803 { return wxT( "" ); }
virtual void mpScaleBase::formatLabels ( )
inlineprotectedvirtualinherited
const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 305 of file mathplot.h.

305 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:315
wxBitmap mpLayer::GetColourSquare ( int  side = 16)
inherited

Get a small square bitmap filled with the colour of the pen used in the layer.

Useful to create legends or similar reference to the layers.

Parameters
sideside length in pixels
Returns
a wxBitmap filled with layer's colour

Definition at line 82 of file mathplot.cpp.

References mpLayer::m_pen, and square().

83 {
84  wxBitmap square( side, side, -1 );
85  wxColour filler = m_pen.GetColour();
86  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
87  wxMemoryDC dc;
88 
89  dc.SelectObject( square );
90  dc.SetBackground( brush );
91  dc.Clear();
92  dc.SelectObject( wxNullBitmap );
93  return square;
94 }
static double square(int x)
Definition: trigo.cpp:138
wxPen m_pen
Definition: mathplot.h:314
bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 257 of file mathplot.h.

257 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:317
void mpScaleBase::GetDataRange ( double &  minV,
double &  maxV 
)
inlineinherited

Definition at line 725 of file mathplot.h.

Referenced by mpScaleX::recalculateTicks(), mpScaleXLog::recalculateTicks(), and recalculateTicks().

726  {
727  minV = m_minV;
728  maxV = m_maxV;
729  }
double m_maxV
Definition: mathplot.h:829
double m_minV
Definition: mathplot.h:829
bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 284 of file mathplot.h.

284 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 242 of file mathplot.h.

242 { return m_font; }
wxFont m_font
Definition: mathplot.h:309
virtual const wxString mpScaleBase::getLabel ( int  n)
inlineprotectedvirtualinherited

Definition at line 816 of file mathplot.h.

Referenced by mpScaleBase::computeLabelExtents(), and Plot().

817  {
818  return m_tickLabels[n].label;
819  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
virtual double mpScaleBase::getLabelPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 811 of file mathplot.h.

Referenced by mpScaleXBase::Plot(), and Plot().

812  {
813  return m_tickLabels[n].pos;
814  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
mpLayerType mpLayer::GetLayerType ( )
inlineinherited

Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.

Returns
An integer indicating layer type

Definition at line 293 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320
virtual double mpLayer::GetMaxX ( )
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 179 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

179 { return 1.0; }
virtual double mpLayer::GetMaxY ( )
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 189 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

189 { return 1.0; }
virtual double mpLayer::GetMinX ( )
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 174 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

174 { return -1.0; }
virtual double mpLayer::GetMinY ( )
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 184 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

184 { return -1.0; }
const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::GetLabelX(), SIM_PLOT_PANEL::GetLabelY1(), SIM_PLOT_PANEL::GetLabelY2(), mpInfoLegend::Plot(), and mpText::Plot().

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316
const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314
virtual double mpScaleBase::getTickPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 806 of file mathplot.h.

Referenced by mpScaleXBase::Plot(), and Plot().

807  {
808  return m_tickValues[n];
809  }
std::vector< double > m_tickValues
Definition: mathplot.h:821
bool mpScaleY::GetTicks ( )
inline

Get Y axis ticks or grid.

Returns
TRUE if plot is drawing axis ticks, FALSE if the grid is active.

Definition at line 966 of file mathplot.h.

References mpScaleBase::m_ticks.

Referenced by SIM_PLOT_PANEL::IsGridShown().

966 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:994
void mpScaleY::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overrideprotectedvirtual

Reimplemented from mpScaleBase.

Definition at line 1054 of file mathplot.cpp.

References mpWindow::GetMarginBottom(), mpWindow::GetMarginTop(), mpWindow::GetScrY(), mpLayer::m_drawOutsideMargins, mpWindow::p2y(), and TransformFromPlot().

Referenced by computeSlaveTicks(), and recalculateTicks().

1055 {
1056  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1057  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1058 
1059  double pymin = w.p2y( minYpx );
1060  double pymax = w.p2y( maxYpx );
1061 
1062  // printf("PYmin %.3f PYmax %.3f\n", pymin, pymax);
1063 
1064  minV = TransformFromPlot( pymax );
1065  maxV = TransformFromPlot( pymin );
1066 }
int GetMarginBottom()
Get the bottom margin.
Definition: mathplot.h:1344
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1136
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1186
int GetMarginTop()
Get the top margin.
Definition: mathplot.h:1340
bool m_drawOutsideMargins
Definition: mathplot.h:319
virtual double TransformFromPlot(double xplot) override
Definition: mathplot.cpp:3301
virtual bool mpScaleY::HasBBox ( )
inlineoverridevirtual

Check whether this layer has a bounding box.

This implementation returns FALSE thus making the ruler invisible to the plot layer bounding box calculation by mpWindow.

Reimplemented from mpScaleBase.

Definition at line 954 of file mathplot.h.

954 { return FALSE; }
virtual bool mpScaleY::IsHorizontal ( )
inlineoverridevirtual

Implements mpScaleBase.

Definition at line 943 of file mathplot.h.

943 { return false; }
virtual bool mpLayer::IsInfo ( )
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns FALSE. It is overrided to TRUE for mpInfoLayer class and its derivative. It is necessary to define mouse actions behaviour over info boxes.

Returns
whether the layer is an info boxes
See also
mpInfoLayer::IsInfo

Reimplemented in mpInfoLayer.

Definition at line 169 of file mathplot.h.

169 { return false; };
bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

Referenced by mpWindow::IsLayerVisible(), SIM_PLOT_PANEL::IsLegendShown(), and mpInfoLegend::Plot().

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321
virtual int mpScaleBase::labelCount ( ) const
inlineprotectedvirtualinherited

Definition at line 798 of file mathplot.h.

Referenced by mpScaleBase::computeLabelExtents(), mpScaleXBase::Plot(), and Plot().

799  {
800  return m_tickLabels.size();
801  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
void mpScaleY::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtual

Layer plot handler.

This implementation will plot the ruler adjusted to the visible area.

Implements mpLayer.

Definition at line 1517 of file mathplot.cpp.

References mpScaleBase::getLabel(), mpScaleBase::getLabelPos(), mpWindow::GetMarginBottom(), mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetMarginTop(), mpWindow::GetPosY(), mpWindow::GetScaleY(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), mpLayer::m_drawOutsideMargins, m_flags, mpLayer::m_font, mpScaleBase::m_maxV, mpScaleBase::m_minV, mpLayer::m_name, mpScaleBase::m_nameFlags, mpScaleBase::m_offset, mpLayer::m_pen, mpScaleBase::m_scale, mpScaleBase::m_tickLabels, m_ticks, mpLayer::m_visible, mpALIGN_BORDER_LEFT, mpALIGN_BORDER_RIGHT, mpALIGN_CENTER, mpALIGN_LEFT, mpALIGN_RIGHT, recalculateTicks(), mpScaleBase::tickCount(), TransformToPlot(), mpWindow::x2p(), and Y_BORDER_SEPARATION.

1518 {
1519  m_offset = -m_minV;
1520  m_scale = 1.0 / ( m_maxV - m_minV );
1521 
1522  // printf("Plot Y-scale\n");
1523  recalculateTicks( dc, w );
1524 
1525  if( m_visible )
1526  {
1527  dc.SetPen( m_pen );
1528  dc.SetFont( m_font );
1529 
1530  int orgx = 0;
1531 
1532  // const int extend = w.GetScrY(); // /2;
1533  if( m_flags == mpALIGN_CENTER )
1534  orgx = w.x2p( 0 ); // (int)(w.GetPosX() * w.GetScaleX());
1535 
1536  if( m_flags == mpALIGN_LEFT )
1537  {
1538  if( m_drawOutsideMargins )
1539  orgx = Y_BORDER_SEPARATION;
1540  else
1541  orgx = w.GetMarginLeft();
1542  }
1543 
1544  if( m_flags == mpALIGN_RIGHT )
1545  {
1546  if( m_drawOutsideMargins )
1547  orgx = w.GetScrX() - Y_BORDER_SEPARATION;
1548  else
1549  orgx = w.GetScrX() - w.GetMarginRight();
1550  }
1551 
1552  if( m_flags == mpALIGN_BORDER_RIGHT )
1553  orgx = w.GetScrX() - 1; // dc.LogicalToDeviceX(0) - 1;
1554 
1555  if( m_flags == mpALIGN_BORDER_LEFT )
1556  orgx = 1; // -dc.LogicalToDeviceX(0);
1557 
1558  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1559  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1560  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1561  // Draw line
1562  dc.DrawLine( orgx, minYpx, orgx, maxYpx );
1563 
1564 
1565  wxCoord tx, ty;
1566  wxString s;
1567  wxString fmt;
1568  int n = 0;
1569 
1570 
1571  int labelW = 0;
1572  // Before staring cycle, calculate label height
1573  int labelHeigth = 0;
1574  s.Printf( fmt, n );
1575  dc.GetTextExtent( s, &tx, &labelHeigth );
1576 
1577  // printf("Y-ticks: %d\n", tickCount());
1578  for( n = 0; n < tickCount(); n++ )
1579  {
1580  // printf("Tick %d\n", n);
1581 
1582  double tp = getTickPos( n );
1583 
1584  double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1585  const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1586 
1587 
1588  if( (p >= minYpx) && (p <= maxYpx) )
1589  {
1590  if( m_ticks ) // Draw axis ticks
1591  {
1592  if( m_flags == mpALIGN_BORDER_LEFT )
1593  {
1594  dc.DrawLine( orgx, p, orgx + 4, p );
1595  }
1596  else
1597  {
1598  dc.DrawLine( orgx - 4, p, orgx, p ); // ( orgx, p, orgx+4, p);
1599  }
1600  }
1601  else
1602  {
1603  dc.DrawLine( orgx - 4, p, orgx + 4, p );
1604 
1605  m_pen.SetStyle( wxPENSTYLE_DOT );
1606  dc.SetPen( m_pen );
1607 
1609  {
1610  dc.DrawLine( orgx - 4, p, endPx, p );
1611  }
1612  else
1613  {
1615  {
1616  // dc.DrawLine( orgX-4, p, orgx+4, p);
1617  dc.DrawLine( orgx - 4, p, endPx, p );
1618  }
1619  else
1620  {
1621  dc.DrawLine( orgx - 4, p, endPx, p );
1622  // dc.DrawLine( orgx-4/*-w.GetScrX()*/, p, w.GetScrX(), p);
1623  }
1624  }
1625 
1626  m_pen.SetStyle( wxPENSTYLE_SOLID );
1627  dc.SetPen( m_pen );
1628  }
1629 
1630  // Print ticks labels
1631  }
1632  }
1633 
1634  // printf("Y-ticks: %d\n", tickCount());
1635  for( n = 0; n < labelCount(); n++ )
1636  {
1637  // printf("Tick %d\n", n);
1638 
1639  double tp = getLabelPos( n );
1640 
1641  double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1642  const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1643 
1644  if( !m_tickLabels[n].visible )
1645  continue;
1646 
1647  if( (p >= minYpx) && (p <= maxYpx) )
1648  {
1649  s = getLabel( n );
1650  dc.GetTextExtent( s, &tx, &ty );
1651 
1653  dc.DrawText( s, orgx + 4, p - ty / 2 );
1654  else
1655  dc.DrawText( s, orgx - 4 - tx, p - ty / 2 ); // ( s, orgx+4, p-ty/2);
1656  }
1657  }
1658 
1659  // Draw axis name
1660  // Draw axis name
1661 
1662  dc.GetTextExtent( m_name, &tx, &ty );
1663 
1664  switch( m_nameFlags )
1665  {
1666  case mpALIGN_BORDER_LEFT:
1667  dc.DrawText( m_name, labelW + 8, 4 );
1668  break;
1669 
1670  case mpALIGN_LEFT:
1671  {
1672  // if ((!m_drawOutsideMargins) && (w.GetMarginLeft() > (ty + labelW + 8))) {
1673  // dc.DrawRotatedText( m_name, orgx - 6 - labelW - ty, (maxYpx + minYpx) / 2 + tx / 2, 90);
1674  // } else {
1675  dc.DrawText( m_name, orgx + 4, minYpx - ty - 4 );
1676  // }
1677  }
1678  break;
1679 
1680  case mpALIGN_CENTER:
1681  dc.DrawText( m_name, orgx + 4, 4 );
1682  break;
1683 
1684  case mpALIGN_RIGHT:
1685  {
1686  // dc.DrawRotatedText( m_name, orgx + 6, (maxYpx + minYpx) / 2 + tx / 2, 90);
1687 
1688  /*if ((!m_drawOutsideMargins) && (w.GetMarginRight() > (ty + labelW + 8))) {
1689  * dc.DrawRotatedText( m_name, orgx + 6 + labelW, (maxYpx - minYpx + tx)>>1, 90);
1690  * } else {*/
1691  dc.DrawText( m_name, orgx - tx - 4, minYpx - ty - 4 );
1692  // }
1693  }
1694  break;
1695 
1696  case mpALIGN_BORDER_RIGHT:
1697  dc.DrawText( m_name, orgx - 6 - tx - labelW, 4 );
1698  break;
1699 
1700  default:
1701  break;
1702  }
1703  }
1704 }
double m_maxV
Definition: mathplot.h:829
#define mpALIGN_LEFT
Aligns label to the left.
Definition: mathplot.h:480
virtual double TransformToPlot(double x) override
Definition: mathplot.cpp:3295
int tickCount() const
Definition: mathplot.h:793
double m_offset
Definition: mathplot.h:824
#define Y_BORDER_SEPARATION
Definition: mathplot.h:94
int GetMarginBottom()
Get the bottom margin.
Definition: mathplot.h:1344
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1136
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:476
double GetPosY(void) const
Definition: mathplot.h:1119
bool m_visible
Definition: mathplot.h:321
#define mpALIGN_BORDER_LEFT
Aligns Y axis to left border.
Definition: mathplot.h:500
int GetMarginTop()
Get the top margin.
Definition: mathplot.h:1340
virtual int labelCount() const
Definition: mathplot.h:798
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
Definition: mathplot.cpp:1120
int m_flags
Definition: mathplot.h:993
virtual double getLabelPos(int n)
Definition: mathplot.h:811
bool m_ticks
Definition: mathplot.h:994
wxFont m_font
Definition: mathplot.h:309
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1127
double GetScaleY(void) const
Definition: mathplot.h:1105
double m_minV
Definition: mathplot.h:829
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Get the right margin.
Definition: mathplot.h:1342
int GetMarginLeft()
Get the left margin.
Definition: mathplot.h:1346
virtual const wxString getLabel(int n)
Definition: mathplot.h:816
double m_scale
Definition: mathplot.h:824
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1191
wxPen m_pen
Definition: mathplot.h:314
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:478
wxString m_name
Definition: mathplot.h:316
int m_nameFlags
Definition: mathplot.h:827
virtual double getTickPos(int n)
Definition: mathplot.h:806
#define mpALIGN_BORDER_RIGHT
Aligns Y axis to right border.
Definition: mathplot.h:502
void mpScaleY::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
overrideprotectedvirtual

Reimplemented from mpScaleBase.

Definition at line 1120 of file mathplot.cpp.

References abs, computeSlaveTicks(), mpScaleBase::GetDataRange(), getVisibleDataRange(), mpScaleBase::m_absVisibleMaxV, m_masterScale, mpScaleBase::m_tickLabels, mpScaleBase::m_tickValues, max, and mpScaleBase::updateTickLabels().

Referenced by Plot().

1121 {
1122  // printf("this %p master %p\n", this, m_masterScale);
1123 
1124  if( m_masterScale )
1125  {
1126  computeSlaveTicks( w );
1127  updateTickLabels( dc, w );
1128 
1129  return;
1130  }
1131 
1132  double minV, maxV, minVvis, maxVvis;
1133  GetDataRange( minV, maxV );
1134  getVisibleDataRange( w, minVvis, maxVvis );
1135  // printf("vdr %.10f %.10f\n", minVvis, maxVvis);
1136 
1137  m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
1138 
1139 
1140  m_tickValues.clear();
1141  m_tickLabels.clear();
1142 
1143 
1144  double minErr = 1000000000000.0;
1145  double bestStep = 1.0;
1146 
1147  for( int i = 10; i <= 20; i += 2 )
1148  {
1149  double curr_step = fabs( maxVvis - minVvis ) / (double) i;
1150  double base = pow( 10, floor( log10( curr_step ) ) );
1151 
1152  // printf("base %.3f\n", base);
1153 
1154  double stepInt = floor( curr_step / base ) * base;
1155  double err = fabs( curr_step - stepInt );
1156 
1157  if( err< minErr )
1158  {
1159  minErr = err;
1160  bestStep = stepInt;
1161  }
1162 
1163  // printf("curr_step %d %.3f %.3f best %.3f\n",i, curr_step, stepInt, bestStep);
1164  }
1165 
1166 
1167  double v = floor( minVvis / bestStep ) * bestStep;
1168 
1169  double zeroOffset = 100000000.0;
1170  // printf("v %.3f maxVVis %.3f\n", v, maxVvis);
1171 
1172  const int iterLimit = 1000;
1173  int i = 0;
1174 
1175  while( v < maxVvis && i < iterLimit )
1176  {
1177  m_tickValues.push_back( v );
1178 
1179  if( fabs( v ) < zeroOffset )
1180  zeroOffset = fabs( v );
1181 
1182  // printf("tick %.3f %d\n", v, m_tickValues.size());
1183  v += bestStep;
1184  i++;
1185  }
1186 
1187 
1188  // something weird happened...
1189  if( i == iterLimit )
1190  {
1191  m_tickValues.clear();
1192  }
1193 
1194  if( zeroOffset <= bestStep )
1195  {
1196  for( double& t : m_tickValues )
1197  t -= zeroOffset;
1198  }
1199 
1200  for( double t : m_tickValues )
1201  m_tickLabels.push_back( TickLabel( t ) );
1202 
1203 
1204  // n0 = floor(minVvis / bestStep) * bestStep;
1205  // end = n0 +
1206 
1207  // n0 = floor( (w.GetPosX() ) / step ) * step ;
1208  // printf("zeroOffset:%.3f tickjs : %d\n", zeroOffset, m_tickValues.size());
1209  updateTickLabels( dc, w );
1210 
1211  // labelStep = ceil(((double) m_maxLabelWidth + mpMIN_X_AXIS_LABEL_SEPARATION)/(w.GetScaleX()*step))*step;
1212 }
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:725
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:978
void computeSlaveTicks(mpWindow &w)
Definition: mathplot.cpp:1069
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
#define abs(a)
Definition: auxiliary.h:84
double m_absVisibleMaxV
Definition: mathplot.h:825
#define max(a, b)
Definition: auxiliary.h:86
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1054
mpScaleY * m_masterScale
Definition: mathplot.h:989
std::vector< double > m_tickValues
Definition: mathplot.h:821
void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 752 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::ResetScales().

753  {
754  m_rangeSet = 0;
755  }
bool m_rangeSet
Definition: mathplot.h:830
void mpScaleY::SetAlign ( int  align)
inline

Set Y axis alignment.

Parameters
alignalignment (choose between mpALIGN_BORDER_LEFT, mpALIGN_LEFT, mpALIGN_CENTER, mpALIGN_RIGHT, mpALIGN_BORDER_RIGHT)

Definition at line 958 of file mathplot.h.

958 { m_flags = align; };
int m_flags
Definition: mathplot.h:993
void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 309 of file mathplot.h.

309 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:315
void mpLayer::SetContinuity ( bool  continuity)
inlineinherited

Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).

See also
GetContinuity

Definition at line 252 of file mathplot.h.

Referenced by TRACE::TRACE().

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317
void mpScaleBase::SetDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 718 of file mathplot.h.

719  {
720  m_rangeSet = true;
721  m_minV = minV;
722  m_maxV = maxV;
723  }
double m_maxV
Definition: mathplot.h:829
bool m_rangeSet
Definition: mathplot.h:830
double m_minV
Definition: mathplot.h:829
void mpLayer::SetDrawOutsideMargins ( bool  drawModeOutside)
inlineinherited

Set Draw mode: inside or outside margins.

Default is outside, which allows the layer to draw up to the mpWindow border.

Parameters
drawModeOutsideThe draw mode to be set

Definition at line 280 of file mathplot.h.

Referenced by CURSOR::CURSOR(), and TRACE::TRACE().

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 271 of file mathplot.h.

271 { m_font = font; }
wxFont m_font
Definition: mathplot.h:309
void mpScaleY::SetMasterScale ( mpScaleY masterScale)
inline

Definition at line 972 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::AddTrace(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

973  {
974  m_masterScale = masterScale;
975  }
mpScaleY * m_masterScale
Definition: mathplot.h:989
void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 266 of file mathplot.h.

266 { m_name = name; }
wxString m_name
Definition: mathplot.h:316
void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 704 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

704 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:827
void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 276 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::AddTrace().

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314
void mpScaleY::SetTicks ( bool  ticks)
inline

Set Y axis ticks or grid.

Parameters
ticksTRUE to plot axis ticks, FALSE to plot grid.

Definition at line 962 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::ShowGrid(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

962 { m_ticks = ticks; };
bool m_ticks
Definition: mathplot.h:994
void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

Referenced by mpWindow::SetLayerVisible(), SIM_PLOT_PANEL::ShowLegend(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321
void mpLayer::ShowName ( bool  show)
inlineinherited

Shows or hides the text label with the name of the layer (default is visible).

Definition at line 261 of file mathplot.h.

Referenced by TRACE::TRACE().

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318
int mpScaleBase::tickCount ( ) const
inlineprotectedinherited

Definition at line 793 of file mathplot.h.

Referenced by mpScaleXBase::Plot(), and Plot().

794  {
795  return m_tickValues.size();
796  }
std::vector< double > m_tickValues
Definition: mathplot.h:821
std::vector<TickLabel>& mpScaleBase::TickLabels ( )
inlineinherited

Definition at line 782 of file mathplot.h.

Referenced by FREQUENCY_LOG_SCALE::formatLabels(), and formatSILabels().

782 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
double mpScaleY::TransformFromPlot ( double  xplot)
overridevirtual

Reimplemented from mpScaleBase.

Definition at line 3301 of file mathplot.cpp.

References mpScaleBase::m_offset, and mpScaleBase::m_scale.

Referenced by computeSlaveTicks(), and getVisibleDataRange().

3302 {
3303  return xplot / m_scale - m_offset;
3304 }
double m_offset
Definition: mathplot.h:824
double m_scale
Definition: mathplot.h:824
double mpScaleY::TransformToPlot ( double  x)
overridevirtual

Reimplemented from mpScaleBase.

Definition at line 3295 of file mathplot.cpp.

References mpScaleBase::m_offset, and mpScaleBase::m_scale.

Referenced by computeSlaveTicks(), and Plot().

3296 {
3297  return (x + m_offset) * m_scale;
3298 }
double m_offset
Definition: mathplot.h:824
double m_scale
Definition: mathplot.h:824
void mpScaleBase::updateTickLabels ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 978 of file mathplot.cpp.

References mpScaleBase::computeLabelExtents(), and mpScaleBase::formatLabels().

Referenced by mpScaleX::recalculateTicks(), mpScaleXLog::recalculateTicks(), and recalculateTicks().

979 {
980  formatLabels();
981  computeLabelExtents( dc, w );
982 
983  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
984 
985  // if ( m_tickLabels.size() <= 2)
986  // return;
987 
988  /*
989  * fixme!
990  *
991  * for ( auto &l : m_tickLabels )
992  * {
993  * double p = TransformToPlot ( l.pos );
994  *
995  * if ( !IsHorizontal() )
996  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
997  * else
998  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
999  * }
1000  *
1001  *
1002  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
1003  * {
1004  * int dist_prev;
1005  *
1006  * for(int j = i-1; j >= 1; j--)
1007  * {
1008  * if( m_tickLabels[j].visible)
1009  * {
1010  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
1011  * break;
1012  * }
1013  * }
1014  *
1015  * if (dist_prev < gap)
1016  * m_tickLabels[i].visible = false;
1017  * }
1018  */
1019 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:960
virtual void formatLabels()
Definition: mathplot.h:804

Member Data Documentation

double mpScaleBase::m_absVisibleMaxV
protectedinherited
wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

Referenced by CURSOR::Plot(), mpFXY::Plot(), and mpMovableObject::Plot().

bool mpLayer::m_drawOutsideMargins
protectedinherited
int mpScaleY::m_flags
protected

Definition at line 993 of file mathplot.h.

Referenced by Plot().

mpScaleY* mpScaleY::m_masterScale
protected

Definition at line 989 of file mathplot.h.

Referenced by computeSlaveTicks(), and recalculateTicks().

int mpScaleBase::m_maxLabelHeight
protectedinherited
int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 832 of file mathplot.h.

Referenced by mpScaleBase::computeLabelExtents(), and mpScaleBase::mpScaleBase().

double mpScaleBase::m_maxV
protectedinherited
double mpScaleBase::m_minV
protectedinherited
wxString mpLayer::m_name
protectedinherited
int mpScaleBase::m_nameFlags
protectedinherited

Definition at line 827 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase(), mpScaleXBase::Plot(), and Plot().

bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 830 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase().

bool mpLayer::m_showName
protectedinherited
std::vector<TickLabel> mpScaleBase::m_tickLabels
protectedinherited
bool mpScaleY::m_ticks
protected

Definition at line 994 of file mathplot.h.

Referenced by Plot().

std::vector<double> mpScaleBase::m_tickValues
protectedinherited
mpLayerType mpLayer::m_type
protectedinherited

Definition at line 320 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().


The documentation for this class was generated from the following files: