KiCad PCB EDA Suite
GAIN_SCALE Class Reference
Inheritance diagram for GAIN_SCALE:
mpScaleY mpScaleBase mpLayer

Public Member Functions

 GAIN_SCALE (wxString name, int flags)
 
void formatLabels () override
 
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 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

Definition at line 212 of file sim_plot_panel.cpp.

Constructor & Destructor Documentation

GAIN_SCALE::GAIN_SCALE ( wxString  name,
int  flags 
)
inline

Definition at line 215 of file sim_plot_panel.cpp.

215  :
216  mpScaleY( name, flags, false ) {};
mpScaleY(const wxString &name=wxT("Y"), int flags=mpALIGN_CENTER, bool ticks=true)
Definition: mathplot.cpp:1531
const char * name
Definition: DXF_plotter.cpp:61

Member Function Documentation

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 761 of file mathplot.h.

References abs, and max.

762  {
763  return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
764  }
double m_maxV
Definition: mathplot.h:833
#define abs(a)
Definition: auxiliary.h:84
double m_minV
Definition: mathplot.h:833
#define max(a, b)
Definition: auxiliary.h:86
double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 766 of file mathplot.h.

Referenced by formatSILabels().

767  {
768  return m_absVisibleMaxV;
769  }
double m_absVisibleMaxV
Definition: mathplot.h:829
void mpScaleY::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protectedinherited
void mpScaleY::computeSlaveTicks ( mpWindow w)
protectedinherited

Definition at line 1096 of file mathplot.cpp.

References i, and max.

1097 {
1098  if( m_masterScale->m_tickValues.size() == 0 )
1099  return;
1100 
1101  m_tickValues.clear();
1102  m_tickLabels.clear();
1103 
1104  // printf("NTicks %d\n", m_masterScale->m_tickValues.size());
1107 
1108  m_scale = 1.0 / ( m_maxV - m_minV );
1109  m_offset = -m_minV;
1110 
1111  double y_slave0 = p0 / m_scale;
1112  double y_slave1 = p1 / m_scale;
1113 
1114  double dy_slave = (y_slave1 - y_slave0);
1115  double exponent = floor( log10( dy_slave ) );
1116  double base = dy_slave / pow( 10.0, exponent );
1117 
1118  double dy_scaled = ceil( 2.0 * base ) / 2.0 * pow( 10.0, exponent );
1119 
1120  double minvv, maxvv;
1121 
1122  getVisibleDataRange( w, minvv, maxvv );
1123 
1124  minvv = floor( minvv / dy_scaled ) * dy_scaled;
1125 
1126  m_scale = 1.0 / ( m_maxV - m_minV );
1127  m_scale *= dy_slave / dy_scaled;
1128 
1129  m_offset = p0 / m_scale - minvv;
1130 
1131  m_tickValues.clear();
1132 
1133  double m;
1134 
1135  m_absVisibleMaxV = 0;
1136 
1137  for( unsigned int i = 0; i < m_masterScale->m_tickValues.size(); i++ )
1138  {
1140  m_tickValues.push_back( m );
1141  m_tickLabels.push_back( TickLabel( m ) );
1142  m_absVisibleMaxV = std::max( m_absVisibleMaxV, fabs( m ) );
1143  }
1144 }
double m_maxV
Definition: mathplot.h:833
virtual double TransformToPlot(double x) override
Definition: mathplot.cpp:3322
double m_offset
Definition: mathplot.h:828
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
double m_absVisibleMaxV
Definition: mathplot.h:829
double m_minV
Definition: mathplot.h:833
double m_scale
Definition: mathplot.h:828
#define max(a, b)
Definition: auxiliary.h:86
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1081
size_t i
Definition: json11.cpp:597
virtual double TransformFromPlot(double xplot) override
Definition: mathplot.cpp:3328
mpScaleY * m_masterScale
Definition: mathplot.h:993
std::vector< double > m_tickValues
Definition: mathplot.h:825
void mpScaleBase::ExtendDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 735 of file mathplot.h.

References max, and min.

736  {
737  if( !m_rangeSet )
738  {
739  m_minV = minV;
740  m_maxV = maxV;
741  m_rangeSet = true;
742  }
743  else
744  {
745  m_minV = std::min( minV, m_minV );
746  m_maxV = std::max( maxV, m_maxV );
747  }
748 
749  if( m_minV == m_maxV )
750  {
751  m_minV = m_minV - 1.0;
752  m_maxV = m_maxV + 1.0;
753  }
754  }
double m_maxV
Definition: mathplot.h:833
bool m_rangeSet
Definition: mathplot.h:834
double m_minV
Definition: mathplot.h:833
#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 807 of file mathplot.h.

807 { return wxT( "" ); }
void GAIN_SCALE::formatLabels ( )
inlineoverridevirtual

Reimplemented from mpScaleBase.

Definition at line 218 of file sim_plot_panel.cpp.

References formatSILabels().

219  {
220  formatSILabels( this, wxT( "dBV" ), 3 );
221  }
static void formatSILabels(mpScaleBase *scale, const wxString &aUnit, int nDigits)
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 83 of file mathplot.cpp.

References mpLayer::m_pen.

84 {
85  wxBitmap square( side, side, -1 );
86  wxColour filler = m_pen.GetColour();
87  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
88  wxMemoryDC dc;
89 
90  dc.SelectObject( square );
91  dc.SetBackground( brush );
92  dc.Clear();
93  dc.SelectObject( wxNullBitmap );
94  return square;
95 }
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 729 of file mathplot.h.

730  {
731  minV = m_minV;
732  maxV = m_maxV;
733  }
double m_maxV
Definition: mathplot.h:833
double m_minV
Definition: mathplot.h:833
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 820 of file mathplot.h.

Referenced by mpScaleY::Plot(), and mpScaleBase::updateTickLabels().

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

Definition at line 815 of file mathplot.h.

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

816  {
817  return m_tickLabels[n].pos;
818  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
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().

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().

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().

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().

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 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 810 of file mathplot.h.

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

811  {
812  return m_tickValues[n];
813  }
std::vector< double > m_tickValues
Definition: mathplot.h:825
bool mpScaleY::GetTicks ( )
inlineinherited

Get Y axis ticks or grid.

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

Definition at line 970 of file mathplot.h.

970 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:998
void mpScaleY::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overrideprotectedvirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1081 of file mathplot.cpp.

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

1082 {
1083  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1084  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1085 
1086  double pymin = w.p2y( minYpx );
1087  double pymax = w.p2y( maxYpx );
1088 
1089  // printf("PYmin %.3f PYmax %.3f\n", pymin, pymax);
1090 
1091  minV = TransformFromPlot( pymax );
1092  maxV = TransformFromPlot( pymin );
1093 }
int GetMarginBottom()
Definition: mathplot.h:1350
int GetScrY(void) const
Get current view&#39;s Y dimension in device context units.
Definition: mathplot.h:1140
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1190
int GetMarginTop()
Definition: mathplot.h:1346
bool m_drawOutsideMargins
Definition: mathplot.h:319
virtual double TransformFromPlot(double xplot) override
Definition: mathplot.cpp:3328
virtual bool mpScaleY::HasBBox ( )
inlineoverridevirtualinherited

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 958 of file mathplot.h.

958 { return FALSE; }
virtual bool mpScaleY::IsHorizontal ( )
inlineoverridevirtualinherited

Implements mpScaleBase.

Definition at line 947 of file mathplot.h.

947 { 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(), and mpInfoLegend::Plot().

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

Definition at line 802 of file mathplot.h.

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

803  {
804  return m_tickLabels.size();
805  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
void mpScaleY::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtualinherited

Layer plot handler.

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

Implements mpLayer.

Definition at line 1544 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, mpScaleBase::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, mpScaleBase::m_ticks, mpLayer::m_visible, mpALIGN_BORDER_LEFT, mpALIGN_BORDER_RIGHT, mpALIGN_CENTER, mpALIGN_LEFT, mpALIGN_RIGHT, mpWindow::OnPaint(), mpWindow::OnScrollBottom(), mpWindow::OnScrollLineDown(), mpWindow::OnScrollLineUp(), mpWindow::OnScrollPageDown(), mpWindow::OnScrollPageUp(), mpWindow::OnScrollThumbTrack(), mpWindow::OnScrollTop(), mpWindow::OnSize(), mpScaleXLog::recalculateTicks(), mpScaleBase::tickCount(), mpScaleXLog::TransformToPlot(), mpWindow::x2p(), and Y_BORDER_SEPARATION.

1545 {
1546  m_offset = -m_minV;
1547  m_scale = 1.0 / ( m_maxV - m_minV );
1548 
1549  // printf("Plot Y-scale\n");
1550  recalculateTicks( dc, w );
1551 
1552  if( m_visible )
1553  {
1554  dc.SetPen( m_pen );
1555  dc.SetFont( m_font );
1556 
1557  int orgx = 0;
1558 
1559  // const int extend = w.GetScrY(); // /2;
1560  if( m_flags == mpALIGN_CENTER )
1561  orgx = w.x2p( 0 ); // (int)(w.GetPosX() * w.GetScaleX());
1562 
1563  if( m_flags == mpALIGN_LEFT )
1564  {
1565  if( m_drawOutsideMargins )
1566  orgx = Y_BORDER_SEPARATION;
1567  else
1568  orgx = w.GetMarginLeft();
1569  }
1570 
1571  if( m_flags == mpALIGN_RIGHT )
1572  {
1573  if( m_drawOutsideMargins )
1574  orgx = w.GetScrX() - Y_BORDER_SEPARATION;
1575  else
1576  orgx = w.GetScrX() - w.GetMarginRight();
1577  }
1578 
1579  if( m_flags == mpALIGN_BORDER_RIGHT )
1580  orgx = w.GetScrX() - 1; // dc.LogicalToDeviceX(0) - 1;
1581 
1582  if( m_flags == mpALIGN_BORDER_LEFT )
1583  orgx = 1; // -dc.LogicalToDeviceX(0);
1584 
1585  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1586  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1587  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1588  // Draw line
1589  dc.DrawLine( orgx, minYpx, orgx, maxYpx );
1590 
1591 
1592  wxCoord tx, ty;
1593  wxString s;
1594  wxString fmt;
1595  int n = 0;
1596 
1597 
1598  int labelW = 0;
1599  // Before staring cycle, calculate label height
1600  int labelHeigth = 0;
1601  s.Printf( fmt, n );
1602  dc.GetTextExtent( s, &tx, &labelHeigth );
1603 
1604  // printf("Y-ticks: %d\n", tickCount());
1605  for( n = 0; n < tickCount(); n++ )
1606  {
1607  // printf("Tick %d\n", n);
1608 
1609  double tp = getTickPos( n );
1610 
1611  double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1612  const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1613 
1614 
1615  if( (p >= minYpx) && (p <= maxYpx) )
1616  {
1617  if( m_ticks ) // Draw axis ticks
1618  {
1619  if( m_flags == mpALIGN_BORDER_LEFT )
1620  {
1621  dc.DrawLine( orgx, p, orgx + 4, p );
1622  }
1623  else
1624  {
1625  dc.DrawLine( orgx - 4, p, orgx, p ); // ( orgx, p, orgx+4, p);
1626  }
1627  }
1628  else
1629  {
1630  dc.DrawLine( orgx - 4, p, orgx + 4, p );
1631 
1632  m_pen.SetStyle( wxPENSTYLE_DOT );
1633  dc.SetPen( m_pen );
1634 
1636  {
1637  dc.DrawLine( orgx - 4, p, endPx, p );
1638  }
1639  else
1640  {
1642  {
1643  // dc.DrawLine( orgX-4, p, orgx+4, p);
1644  dc.DrawLine( orgx - 4, p, endPx, p );
1645  }
1646  else
1647  {
1648  dc.DrawLine( orgx - 4, p, endPx, p );
1649  // dc.DrawLine( orgx-4/*-w.GetScrX()*/, p, w.GetScrX(), p);
1650  }
1651  }
1652 
1653  m_pen.SetStyle( wxPENSTYLE_SOLID );
1654  dc.SetPen( m_pen );
1655  }
1656 
1657  // Print ticks labels
1658  }
1659  }
1660 
1661  // printf("Y-ticks: %d\n", tickCount());
1662  for( n = 0; n < labelCount(); n++ )
1663  {
1664  // printf("Tick %d\n", n);
1665 
1666  double tp = getLabelPos( n );
1667 
1668  double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1669  const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1670 
1671  if( !m_tickLabels[n].visible )
1672  continue;
1673 
1674  if( (p >= minYpx) && (p <= maxYpx) )
1675  {
1676  s = getLabel( n );
1677  dc.GetTextExtent( s, &tx, &ty );
1678 
1680  dc.DrawText( s, orgx + 4, p - ty / 2 );
1681  else
1682  dc.DrawText( s, orgx - 4 - tx, p - ty / 2 ); // ( s, orgx+4, p-ty/2);
1683  }
1684  }
1685 
1686  // Draw axis name
1687  // Draw axis name
1688 
1689  dc.GetTextExtent( m_name, &tx, &ty );
1690 
1691  switch( m_nameFlags )
1692  {
1693  case mpALIGN_BORDER_LEFT:
1694  dc.DrawText( m_name, labelW + 8, 4 );
1695  break;
1696 
1697  case mpALIGN_LEFT:
1698  {
1699  // if ((!m_drawOutsideMargins) && (w.GetMarginLeft() > (ty + labelW + 8))) {
1700  // dc.DrawRotatedText( m_name, orgx - 6 - labelW - ty, (maxYpx + minYpx) / 2 + tx / 2, 90);
1701  // } else {
1702  dc.DrawText( m_name, orgx + 4, minYpx - ty - 4 );
1703  // }
1704  }
1705  break;
1706 
1707  case mpALIGN_CENTER:
1708  dc.DrawText( m_name, orgx + 4, 4 );
1709  break;
1710 
1711  case mpALIGN_RIGHT:
1712  {
1713  // dc.DrawRotatedText( m_name, orgx + 6, (maxYpx + minYpx) / 2 + tx / 2, 90);
1714 
1715  /*if ((!m_drawOutsideMargins) && (w.GetMarginRight() > (ty + labelW + 8))) {
1716  * dc.DrawRotatedText( m_name, orgx + 6 + labelW, (maxYpx - minYpx + tx)>>1, 90);
1717  * } else {*/
1718  dc.DrawText( m_name, orgx - tx - 4, minYpx - ty - 4 );
1719  // }
1720  }
1721  break;
1722 
1723  case mpALIGN_BORDER_RIGHT:
1724  dc.DrawText( m_name, orgx - 6 - tx - labelW, 4 );
1725  break;
1726 
1727  default:
1728  break;
1729  }
1730  }
1731 }
double m_maxV
Definition: mathplot.h:833
#define mpALIGN_LEFT
Aligns label to the left.
Definition: mathplot.h:480
virtual double TransformToPlot(double x) override
Definition: mathplot.cpp:3322
int tickCount() const
Definition: mathplot.h:797
double m_offset
Definition: mathplot.h:828
#define Y_BORDER_SEPARATION
Definition: mathplot.h:94
int GetMarginBottom()
Definition: mathplot.h:1350
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
int GetScrY(void) const
Get current view&#39;s Y dimension in device context units.
Definition: mathplot.h:1140
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:476
double GetPosY(void) const
Definition: mathplot.h:1123
bool m_visible
Definition: mathplot.h:321
#define mpALIGN_BORDER_LEFT
Aligns Y axis to left border.
Definition: mathplot.h:500
int GetMarginTop()
Definition: mathplot.h:1346
virtual int labelCount() const
Definition: mathplot.h:802
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
Definition: mathplot.cpp:1147
int m_flags
Definition: mathplot.h:997
virtual double getLabelPos(int n)
Definition: mathplot.h:815
bool m_ticks
Definition: mathplot.h:998
wxFont m_font
Definition: mathplot.h:309
int GetScrX(void) const
Get current view&#39;s X dimension in device context units.
Definition: mathplot.h:1131
double GetScaleY(void) const
Definition: mathplot.h:1109
double m_minV
Definition: mathplot.h:833
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Definition: mathplot.h:1348
int GetMarginLeft()
Definition: mathplot.h:1352
virtual const wxString getLabel(int n)
Definition: mathplot.h:820
double m_scale
Definition: mathplot.h:828
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1195
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:831
virtual double getTickPos(int n)
Definition: mathplot.h:810
#define mpALIGN_BORDER_RIGHT
Aligns Y axis to right border.
Definition: mathplot.h:502
void mpScaleY::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
overrideprotectedvirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1147 of file mathplot.cpp.

References abs, err, i, and max.

1148 {
1149  // printf("this %p master %p\n", this, m_masterScale);
1150 
1151  if( m_masterScale )
1152  {
1153  computeSlaveTicks( w );
1154  updateTickLabels( dc, w );
1155 
1156  return;
1157  }
1158 
1159  double minV, maxV, minVvis, maxVvis;
1160  GetDataRange( minV, maxV );
1161  getVisibleDataRange( w, minVvis, maxVvis );
1162  // printf("vdr %.10f %.10f\n", minVvis, maxVvis);
1163 
1164  m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
1165 
1166 
1167  m_tickValues.clear();
1168  m_tickLabels.clear();
1169 
1170 
1171  double minErr = 1000000000000.0;
1172  double bestStep = 1.0;
1173 
1174  for( int i = 10; i <= 20; i += 2 )
1175  {
1176  double curr_step = fabs( maxVvis - minVvis ) / (double) i;
1177  double base = pow( 10, floor( log10( curr_step ) ) );
1178 
1179  // printf("base %.3f\n", base);
1180 
1181  double stepInt = floor( curr_step / base ) * base;
1182  double err = fabs( curr_step - stepInt );
1183 
1184  if( err< minErr )
1185  {
1186  minErr = err;
1187  bestStep = stepInt;
1188  }
1189 
1190  // printf("curr_step %d %.3f %.3f best %.3f\n",i, curr_step, stepInt, bestStep);
1191  }
1192 
1193 
1194  double v = floor( minVvis / bestStep ) * bestStep;
1195 
1196  double zeroOffset = 100000000.0;
1197  // printf("v %.3f maxVVis %.3f\n", v, maxVvis);
1198 
1199  const int iterLimit = 1000;
1200  int i = 0;
1201 
1202  while( v < maxVvis && i < iterLimit )
1203  {
1204  m_tickValues.push_back( v );
1205 
1206  if( fabs( v ) < zeroOffset )
1207  zeroOffset = fabs( v );
1208 
1209  // printf("tick %.3f %d\n", v, m_tickValues.size());
1210  v += bestStep;
1211  i++;
1212  }
1213 
1214 
1215  // something weird happened...
1216  if( i == iterLimit )
1217  {
1218  m_tickValues.clear();
1219  }
1220 
1221  if( zeroOffset <= bestStep )
1222  {
1223  for( double& t : m_tickValues )
1224  t -= zeroOffset;
1225  }
1226 
1227  for( double t : m_tickValues )
1228  m_tickLabels.push_back( TickLabel( t ) );
1229 
1230 
1231  // n0 = floor(minVvis / bestStep) * bestStep;
1232  // end = n0 +
1233 
1234  // n0 = floor( (w.GetPosX() ) / step ) * step ;
1235  // printf("zeroOffset:%.3f tickjs : %d\n", zeroOffset, m_tickValues.size());
1236  updateTickLabels( dc, w );
1237 
1238  // labelStep = ceil(((double) m_maxLabelWidth + mpMIN_X_AXIS_LABEL_SEPARATION)/(w.GetScaleX()*step))*step;
1239 }
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:729
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:1005
void computeSlaveTicks(mpWindow &w)
Definition: mathplot.cpp:1096
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
#define abs(a)
Definition: auxiliary.h:84
double m_absVisibleMaxV
Definition: mathplot.h:829
string & err
Definition: json11.cpp:598
#define max(a, b)
Definition: auxiliary.h:86
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1081
size_t i
Definition: json11.cpp:597
mpScaleY * m_masterScale
Definition: mathplot.h:993
std::vector< double > m_tickValues
Definition: mathplot.h:825
void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 756 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::ResetScales().

757  {
758  m_rangeSet = 0;
759  }
bool m_rangeSet
Definition: mathplot.h:834
void mpScaleY::SetAlign ( int  align)
inlineinherited

Set Y axis alignment.

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

Definition at line 962 of file mathplot.h.

962 { m_flags = align; };
int m_flags
Definition: mathplot.h:997
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 722 of file mathplot.h.

723  {
724  m_rangeSet = true;
725  m_minV = minV;
726  m_maxV = maxV;
727  }
double m_maxV
Definition: mathplot.h:833
bool m_rangeSet
Definition: mathplot.h:834
double m_minV
Definition: mathplot.h:833
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.

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

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

Definition at line 976 of file mathplot.h.

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

977  {
978  m_masterScale = masterScale;
979  }
mpScaleY * m_masterScale
Definition: mathplot.h:993
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.

References name.

Referenced by mpFX::mpFX(), mpFXY::mpFXY(), mpFY::mpFY(), mpProfile::mpProfile(), mpScaleXBase::mpScaleXBase(), mpScaleY::mpScaleY(), and mpText::mpText().

266 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:61
wxString m_name
Definition: mathplot.h:316
void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 706 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

706 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:831
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(), mpScaleXBase::mpScaleXBase(), and mpScaleY::mpScaleY().

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

Set Y axis ticks or grid.

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

Definition at line 966 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

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

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

Referenced by mpWindow::SetLayerVisible(), 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 797 of file mathplot.h.

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

798  {
799  return m_tickValues.size();
800  }
std::vector< double > m_tickValues
Definition: mathplot.h:825
std::vector<TickLabel>& mpScaleBase::TickLabels ( )
inlineinherited

Definition at line 786 of file mathplot.h.

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

786 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
double mpScaleY::TransformFromPlot ( double  xplot)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3328 of file mathplot.cpp.

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

3329 {
3330  return xplot / m_scale - m_offset;
3331 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828
double mpScaleY::TransformToPlot ( double  x)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3322 of file mathplot.cpp.

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

3323 {
3324  return (x + m_offset) * m_scale;
3325 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828
void mpScaleBase::updateTickLabels ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 1005 of file mathplot.cpp.

References mpScaleBase::getLabel(), mpScaleBase::getLabelPos(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), and mpScaleBase::tickCount().

1006 {
1007  formatLabels();
1008  computeLabelExtents( dc, w );
1009 
1010  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
1011 
1012  // if ( m_tickLabels.size() <= 2)
1013  // return;
1014 
1015  /*
1016  * fixme!
1017  *
1018  * for ( auto &l : m_tickLabels )
1019  * {
1020  * double p = TransformToPlot ( l.pos );
1021  *
1022  * if ( !IsHorizontal() )
1023  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
1024  * else
1025  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
1026  * }
1027  *
1028  *
1029  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
1030  * {
1031  * int dist_prev;
1032  *
1033  * for(int j = i-1; j >= 1; j--)
1034  * {
1035  * if( m_tickLabels[j].visible)
1036  * {
1037  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
1038  * break;
1039  * }
1040  * }
1041  *
1042  * if (dist_prev < gap)
1043  * m_tickLabels[i].visible = false;
1044  * }
1045  */
1046 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:987
virtual void formatLabels()
Definition: mathplot.h:808

Member Data Documentation

double mpScaleBase::m_absVisibleMaxV
protectedinherited

Definition at line 829 of file mathplot.h.

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

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

int mpScaleY::m_flags
protectedinherited

Definition at line 997 of file mathplot.h.

wxFont mpLayer::m_font
protectedinherited
mpScaleY* mpScaleY::m_masterScale
protectedinherited

Definition at line 993 of file mathplot.h.

int mpScaleBase::m_maxLabelHeight
protectedinherited

Definition at line 835 of file mathplot.h.

Referenced by mpScaleXBase::Plot().

int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 836 of file mathplot.h.

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

Definition at line 831 of file mathplot.h.

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

double mpScaleBase::m_offset
protectedinherited
bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 834 of file mathplot.h.

double mpScaleBase::m_scale
protectedinherited
bool mpLayer::m_showName
protectedinherited

Definition at line 318 of file mathplot.h.

Referenced by mpFX::Plot(), mpFY::Plot(), and mpFXY::Plot().

std::vector<TickLabel> mpScaleBase::m_tickLabels
protectedinherited

Definition at line 826 of file mathplot.h.

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

bool mpScaleY::m_ticks
protectedinherited

Definition at line 998 of file mathplot.h.

std::vector<double> mpScaleBase::m_tickValues
protectedinherited

Definition at line 825 of file mathplot.h.


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