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

Public Member Functions

 VOLTAGE_SCALE_Y (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 239 of file sim_plot_panel.cpp.

Constructor & Destructor Documentation

◆ VOLTAGE_SCALE_Y()

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

Definition at line 242 of file sim_plot_panel.cpp.

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

Member Function Documentation

◆ AbsMaxValue()

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 761 of file mathplot.h.

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

References abs, and max.

◆ AbsVisibleMaxValue()

double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 766 of file mathplot.h.

767  {
768  return m_absVisibleMaxV;
769  }
double m_absVisibleMaxV
Definition: mathplot.h:829

◆ computeLabelExtents()

void mpScaleY::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protectedinherited

◆ computeSlaveTicks()

void mpScaleY::computeSlaveTicks ( mpWindow w)
protectedinherited

Definition at line 1058 of file mathplot.cpp.

1059 {
1060  if( m_masterScale->m_tickValues.size() == 0 )
1061  return;
1062 
1063  m_tickValues.clear();
1064  m_tickLabels.clear();
1065 
1066  // printf("NTicks %d\n", m_masterScale->m_tickValues.size());
1069 
1070  m_scale = 1.0 / ( m_maxV - m_minV );
1071  m_offset = -m_minV;
1072 
1073  double y_slave0 = p0 / m_scale;
1074  double y_slave1 = p1 / m_scale;
1075 
1076  double dy_slave = (y_slave1 - y_slave0);
1077  double exponent = floor( log10( dy_slave ) );
1078  double base = dy_slave / pow( 10.0, exponent );
1079 
1080  double dy_scaled = ceil( 2.0 * base ) / 2.0 * pow( 10.0, exponent );
1081 
1082  double minvv, maxvv;
1083 
1084  getVisibleDataRange( w, minvv, maxvv );
1085 
1086  minvv = floor( minvv / dy_scaled ) * dy_scaled;
1087 
1088  m_scale = 1.0 / ( m_maxV - m_minV );
1089  m_scale *= dy_slave / dy_scaled;
1090 
1091  m_offset = p0 / m_scale - minvv;
1092 
1093  m_tickValues.clear();
1094 
1095  double m;
1096 
1097  m_absVisibleMaxV = 0;
1098 
1099  for( unsigned int i = 0; i < m_masterScale->m_tickValues.size(); i++ )
1100  {
1102  m_tickValues.push_back( m );
1103  m_tickLabels.push_back( TickLabel( m ) );
1104  m_absVisibleMaxV = std::max( m_absVisibleMaxV, fabs( m ) );
1105  }
1106 }
double m_maxV
Definition: mathplot.h:833
virtual double TransformToPlot(double x) override
Definition: mathplot.cpp:3285
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:1043
size_t i
Definition: json11.cpp:597
virtual double TransformFromPlot(double xplot) override
Definition: mathplot.cpp:3291
mpScaleY * m_masterScale
Definition: mathplot.h:993
std::vector< double > m_tickValues
Definition: mathplot.h:825

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

Referenced by mpScaleY::recalculateTicks().

◆ ExtendDataRange()

void mpScaleBase::ExtendDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 735 of file mathplot.h.

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

References max, and min.

Referenced by mpFXY::UpdateScales().

◆ formatLabel()

virtual const wxString mpScaleBase::formatLabel ( double  value,
int  nDigits 
)
inlineprotectedvirtualinherited

Definition at line 807 of file mathplot.h.

807 { return wxT( "" ); }

◆ formatLabels()

void VOLTAGE_SCALE_Y::formatLabels ( )
inlineoverridevirtual

Reimplemented from mpScaleBase.

Definition at line 245 of file sim_plot_panel.cpp.

246  {
247  formatSILabels( this, wxT( "V" ), 3 );
248  }
static void formatSILabels(mpScaleBase *scale, const wxString &aUnit, int nDigits)

References formatSILabels().

◆ GetBrush()

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

◆ GetColourSquare()

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.

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

References mpLayer::m_pen.

◆ GetContinuity()

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

◆ GetDataRange()

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

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

◆ GetDrawOutsideMargins()

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

◆ GetFont()

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

◆ getLabel()

virtual const wxString mpScaleBase::getLabel ( int  n)
inlineprotectedvirtualinherited

Definition at line 820 of file mathplot.h.

821  {
822  return m_tickLabels[n].label;
823  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826

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

◆ getLabelPos()

virtual double mpScaleBase::getLabelPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 815 of file mathplot.h.

816  {
817  return m_tickLabels[n].pos;
818  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826

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

◆ GetLayerType()

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.

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320

Referenced by mpInfoLegend::Plot().

◆ GetMaxX()

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.

179 { return 1.0; }

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

◆ GetMaxY()

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.

189 { return 1.0; }

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

◆ GetMinX()

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.

174 { return -1.0; }

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

◆ GetMinY()

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.

184 { return -1.0; }

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

◆ GetName()

const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316

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

◆ GetPen()

const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314

Referenced by mpInfoLegend::Plot().

◆ getTickPos()

virtual double mpScaleBase::getTickPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 810 of file mathplot.h.

811  {
812  return m_tickValues[n];
813  }
std::vector< double > m_tickValues
Definition: mathplot.h:825

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

◆ GetTicks()

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

References mpScaleBase::m_ticks.

Referenced by SIM_PLOT_PANEL::IsGridShown().

◆ getVisibleDataRange()

void mpScaleY::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overrideprotectedvirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1043 of file mathplot.cpp.

1044 {
1045  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1046  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1047 
1048  double pymin = w.p2y( minYpx );
1049  double pymax = w.p2y( maxYpx );
1050 
1051  // printf("PYmin %.3f PYmax %.3f\n", pymin, pymax);
1052 
1053  minV = TransformFromPlot( pymax );
1054  maxV = TransformFromPlot( pymin );
1055 }
int GetMarginBottom()
Definition: mathplot.h:1350
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
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:3291
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1140

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

Referenced by mpScaleY::computeSlaveTicks(), and mpScaleY::recalculateTicks().

◆ HasBBox()

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; }

◆ IsHorizontal()

virtual bool mpScaleY::IsHorizontal ( )
inlineoverridevirtualinherited

Implements mpScaleBase.

Definition at line 947 of file mathplot.h.

947 { return false; }

◆ IsInfo()

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; };

◆ IsVisible()

bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321

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

◆ labelCount()

virtual int mpScaleBase::labelCount ( ) const
inlineprotectedvirtualinherited

Definition at line 802 of file mathplot.h.

803  {
804  return m_tickLabels.size();
805  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826

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

◆ Plot()

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 1506 of file mathplot.cpp.

1507 {
1508  m_offset = -m_minV;
1509  m_scale = 1.0 / ( m_maxV - m_minV );
1510 
1511  // printf("Plot Y-scale\n");
1512  recalculateTicks( dc, w );
1513 
1514  if( m_visible )
1515  {
1516  dc.SetPen( m_pen );
1517  dc.SetFont( m_font );
1518 
1519  int orgx = 0;
1520 
1521  // const int extend = w.GetScrY(); // /2;
1522  if( m_flags == mpALIGN_CENTER )
1523  orgx = w.x2p( 0 ); // (int)(w.GetPosX() * w.GetScaleX());
1524 
1525  if( m_flags == mpALIGN_LEFT )
1526  {
1527  if( m_drawOutsideMargins )
1528  orgx = Y_BORDER_SEPARATION;
1529  else
1530  orgx = w.GetMarginLeft();
1531  }
1532 
1533  if( m_flags == mpALIGN_RIGHT )
1534  {
1535  if( m_drawOutsideMargins )
1536  orgx = w.GetScrX() - Y_BORDER_SEPARATION;
1537  else
1538  orgx = w.GetScrX() - w.GetMarginRight();
1539  }
1540 
1541  if( m_flags == mpALIGN_BORDER_RIGHT )
1542  orgx = w.GetScrX() - 1; // dc.LogicalToDeviceX(0) - 1;
1543 
1544  if( m_flags == mpALIGN_BORDER_LEFT )
1545  orgx = 1; // -dc.LogicalToDeviceX(0);
1546 
1547  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1548  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1549  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1550  // Draw line
1551  dc.DrawLine( orgx, minYpx, orgx, maxYpx );
1552 
1553 
1554  wxCoord tx, ty;
1555  wxString s;
1556  wxString fmt;
1557  int n = 0;
1558 
1559 
1560  int labelW = 0;
1561  // Before staring cycle, calculate label height
1562  int labelHeigth = 0;
1563  s.Printf( fmt, n );
1564  dc.GetTextExtent( s, &tx, &labelHeigth );
1565 
1566  // printf("Y-ticks: %d\n", tickCount());
1567  for( n = 0; n < tickCount(); n++ )
1568  {
1569  // printf("Tick %d\n", n);
1570 
1571  double tp = getTickPos( n );
1572 
1573  double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1574  const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1575 
1576 
1577  if( (p >= minYpx) && (p <= maxYpx) )
1578  {
1579  if( m_ticks ) // Draw axis ticks
1580  {
1581  if( m_flags == mpALIGN_BORDER_LEFT )
1582  {
1583  dc.DrawLine( orgx, p, orgx + 4, p );
1584  }
1585  else
1586  {
1587  dc.DrawLine( orgx - 4, p, orgx, p ); // ( orgx, p, orgx+4, p);
1588  }
1589  }
1590  else
1591  {
1592  dc.DrawLine( orgx - 4, p, orgx + 4, p );
1593 
1594  m_pen.SetStyle( wxPENSTYLE_DOT );
1595  dc.SetPen( m_pen );
1596 
1598  {
1599  dc.DrawLine( orgx - 4, p, endPx, p );
1600  }
1601  else
1602  {
1604  {
1605  // dc.DrawLine( orgX-4, p, orgx+4, p);
1606  dc.DrawLine( orgx - 4, p, endPx, p );
1607  }
1608  else
1609  {
1610  dc.DrawLine( orgx - 4, p, endPx, p );
1611  // dc.DrawLine( orgx-4/*-w.GetScrX()*/, p, w.GetScrX(), p);
1612  }
1613  }
1614 
1615  m_pen.SetStyle( wxPENSTYLE_SOLID );
1616  dc.SetPen( m_pen );
1617  }
1618 
1619  // Print ticks labels
1620  }
1621  }
1622 
1623  // printf("Y-ticks: %d\n", tickCount());
1624  for( n = 0; n < labelCount(); n++ )
1625  {
1626  // printf("Tick %d\n", n);
1627 
1628  double tp = getLabelPos( n );
1629 
1630  double py = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1631  const int p = (int) ( ( w.GetPosY() - py ) * w.GetScaleY() );
1632 
1633  if( !m_tickLabels[n].visible )
1634  continue;
1635 
1636  if( (p >= minYpx) && (p <= maxYpx) )
1637  {
1638  s = getLabel( n );
1639  dc.GetTextExtent( s, &tx, &ty );
1640 
1642  dc.DrawText( s, orgx + 4, p - ty / 2 );
1643  else
1644  dc.DrawText( s, orgx - 4 - tx, p - ty / 2 ); // ( s, orgx+4, p-ty/2);
1645  }
1646  }
1647 
1648  // Draw axis name
1649  // Draw axis name
1650 
1651  dc.GetTextExtent( m_name, &tx, &ty );
1652 
1653  switch( m_nameFlags )
1654  {
1655  case mpALIGN_BORDER_LEFT:
1656  dc.DrawText( m_name, labelW + 8, 4 );
1657  break;
1658 
1659  case mpALIGN_LEFT:
1660  {
1661  // if ((!m_drawOutsideMargins) && (w.GetMarginLeft() > (ty + labelW + 8))) {
1662  // dc.DrawRotatedText( m_name, orgx - 6 - labelW - ty, (maxYpx + minYpx) / 2 + tx / 2, 90);
1663  // } else {
1664  dc.DrawText( m_name, orgx + 4, minYpx - ty - 4 );
1665  // }
1666  }
1667  break;
1668 
1669  case mpALIGN_CENTER:
1670  dc.DrawText( m_name, orgx + 4, 4 );
1671  break;
1672 
1673  case mpALIGN_RIGHT:
1674  {
1675  // dc.DrawRotatedText( m_name, orgx + 6, (maxYpx + minYpx) / 2 + tx / 2, 90);
1676 
1677  /*if ((!m_drawOutsideMargins) && (w.GetMarginRight() > (ty + labelW + 8))) {
1678  * dc.DrawRotatedText( m_name, orgx + 6 + labelW, (maxYpx - minYpx + tx)>>1, 90);
1679  * } else {*/
1680  dc.DrawText( m_name, orgx - tx - 4, minYpx - ty - 4 );
1681  // }
1682  }
1683  break;
1684 
1685  case mpALIGN_BORDER_RIGHT:
1686  dc.DrawText( m_name, orgx - 6 - tx - labelW, 4 );
1687  break;
1688 
1689  default:
1690  break;
1691  }
1692  }
1693 }
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:3285
double GetPosY(void) const
Definition: mathplot.h:1123
double m_offset
Definition: mathplot.h:828
#define Y_BORDER_SEPARATION
Definition: mathplot.h:94
double GetScaleY(void) const
Definition: mathplot.h:1109
int GetMarginBottom()
Definition: mathplot.h:1350
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:476
int tickCount() const
Definition: mathplot.h:797
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
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1131
virtual void recalculateTicks(wxDC &dc, mpWindow &w) override
Definition: mathplot.cpp:1109
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
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,...
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 int labelCount() const
Definition: mathplot.h:802
virtual double getTickPos(int n)
Definition: mathplot.h:810
#define mpALIGN_BORDER_RIGHT
Aligns Y axis to right border.
Definition: mathplot.h:502
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1140

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, mpScaleY::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, mpScaleY::m_ticks, mpLayer::m_visible, mpALIGN_BORDER_LEFT, mpALIGN_BORDER_RIGHT, mpALIGN_CENTER, mpALIGN_LEFT, mpALIGN_RIGHT, mpScaleY::recalculateTicks(), mpScaleBase::tickCount(), mpScaleY::TransformToPlot(), mpWindow::x2p(), and Y_BORDER_SEPARATION.

◆ recalculateTicks()

void mpScaleY::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
overrideprotectedvirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1109 of file mathplot.cpp.

1110 {
1111  // printf("this %p master %p\n", this, m_masterScale);
1112 
1113  if( m_masterScale )
1114  {
1115  computeSlaveTicks( w );
1116  updateTickLabels( dc, w );
1117 
1118  return;
1119  }
1120 
1121  double minV, maxV, minVvis, maxVvis;
1122  GetDataRange( minV, maxV );
1123  getVisibleDataRange( w, minVvis, maxVvis );
1124  // printf("vdr %.10f %.10f\n", minVvis, maxVvis);
1125 
1126  m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
1127 
1128 
1129  m_tickValues.clear();
1130  m_tickLabels.clear();
1131 
1132 
1133  double minErr = 1000000000000.0;
1134  double bestStep = 1.0;
1135 
1136  for( int i = 10; i <= 20; i += 2 )
1137  {
1138  double curr_step = fabs( maxVvis - minVvis ) / (double) i;
1139  double base = pow( 10, floor( log10( curr_step ) ) );
1140 
1141  // printf("base %.3f\n", base);
1142 
1143  double stepInt = floor( curr_step / base ) * base;
1144  double err = fabs( curr_step - stepInt );
1145 
1146  if( err< minErr )
1147  {
1148  minErr = err;
1149  bestStep = stepInt;
1150  }
1151 
1152  // printf("curr_step %d %.3f %.3f best %.3f\n",i, curr_step, stepInt, bestStep);
1153  }
1154 
1155 
1156  double v = floor( minVvis / bestStep ) * bestStep;
1157 
1158  double zeroOffset = 100000000.0;
1159  // printf("v %.3f maxVVis %.3f\n", v, maxVvis);
1160 
1161  const int iterLimit = 1000;
1162  int i = 0;
1163 
1164  while( v < maxVvis && i < iterLimit )
1165  {
1166  m_tickValues.push_back( v );
1167 
1168  if( fabs( v ) < zeroOffset )
1169  zeroOffset = fabs( v );
1170 
1171  // printf("tick %.3f %d\n", v, m_tickValues.size());
1172  v += bestStep;
1173  i++;
1174  }
1175 
1176 
1177  // something weird happened...
1178  if( i == iterLimit )
1179  {
1180  m_tickValues.clear();
1181  }
1182 
1183  if( zeroOffset <= bestStep )
1184  {
1185  for( double& t : m_tickValues )
1186  t -= zeroOffset;
1187  }
1188 
1189  for( double t : m_tickValues )
1190  m_tickLabels.push_back( TickLabel( t ) );
1191 
1192 
1193  // n0 = floor(minVvis / bestStep) * bestStep;
1194  // end = n0 +
1195 
1196  // n0 = floor( (w.GetPosX() ) / step ) * step ;
1197  // printf("zeroOffset:%.3f tickjs : %d\n", zeroOffset, m_tickValues.size());
1198  updateTickLabels( dc, w );
1199 
1200  // labelStep = ceil(((double) m_maxLabelWidth + mpMIN_X_AXIS_LABEL_SEPARATION)/(w.GetScaleX()*step))*step;
1201 }
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:729
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:967
void computeSlaveTicks(mpWindow &w)
Definition: mathplot.cpp:1058
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:1043
size_t i
Definition: json11.cpp:597
mpScaleY * m_masterScale
Definition: mathplot.h:993
std::vector< double > m_tickValues
Definition: mathplot.h:825

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

Referenced by mpScaleY::Plot().

◆ ResetDataRange()

void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 756 of file mathplot.h.

757  {
758  m_rangeSet = 0;
759  }
bool m_rangeSet
Definition: mathplot.h:834

Referenced by SIM_PLOT_PANEL::ResetScales().

◆ SetAlign()

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

◆ SetBrush()

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

◆ SetContinuity()

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.

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317

Referenced by TRACE::TRACE().

◆ SetDataRange()

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

◆ SetDrawOutsideMargins()

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.

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319

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

◆ SetFont()

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

◆ SetMasterScale()

void mpScaleY::SetMasterScale ( mpScaleY masterScale)
inlineinherited

Definition at line 976 of file mathplot.h.

977  {
978  m_masterScale = masterScale;
979  }
mpScaleY * m_masterScale
Definition: mathplot.h:993

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

◆ SetName()

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; }
const char * name
Definition: DXF_plotter.cpp:61
wxString m_name
Definition: mathplot.h:316

References name.

◆ SetNameAlign()

void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 706 of file mathplot.h.

706 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:831

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

◆ SetPen()

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.

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314

Referenced by SIM_PLOT_PANEL::AddTrace().

◆ SetTicks()

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.

966 { m_ticks = ticks; };
bool m_ticks
Definition: mathplot.h:998

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

◆ SetVisible()

void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321

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

◆ ShowName()

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.

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318

Referenced by TRACE::TRACE().

◆ tickCount()

int mpScaleBase::tickCount ( ) const
inlineprotectedinherited

Definition at line 797 of file mathplot.h.

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

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

◆ TickLabels()

std::vector<TickLabel>& mpScaleBase::TickLabels ( )
inlineinherited

Definition at line 786 of file mathplot.h.

786 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826

Referenced by FREQUENCY_LOG_SCALE::formatLabels().

◆ TransformFromPlot()

double mpScaleY::TransformFromPlot ( double  xplot)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3291 of file mathplot.cpp.

3292 {
3293  return xplot / m_scale - m_offset;
3294 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828

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

Referenced by mpScaleY::computeSlaveTicks(), and mpScaleY::getVisibleDataRange().

◆ TransformToPlot()

double mpScaleY::TransformToPlot ( double  x)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3285 of file mathplot.cpp.

3286 {
3287  return (x + m_offset) * m_scale;
3288 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828

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

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

◆ updateTickLabels()

void mpScaleBase::updateTickLabels ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 967 of file mathplot.cpp.

968 {
969  formatLabels();
970  computeLabelExtents( dc, w );
971 
972  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
973 
974  // if ( m_tickLabels.size() <= 2)
975  // return;
976 
977  /*
978  * fixme!
979  *
980  * for ( auto &l : m_tickLabels )
981  * {
982  * double p = TransformToPlot ( l.pos );
983  *
984  * if ( !IsHorizontal() )
985  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
986  * else
987  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
988  * }
989  *
990  *
991  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
992  * {
993  * int dist_prev;
994  *
995  * for(int j = i-1; j >= 1; j--)
996  * {
997  * if( m_tickLabels[j].visible)
998  * {
999  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
1000  * break;
1001  * }
1002  * }
1003  *
1004  * if (dist_prev < gap)
1005  * m_tickLabels[i].visible = false;
1006  * }
1007  */
1008 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:949
virtual void formatLabels()
Definition: mathplot.h:808

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

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

Member Data Documentation

◆ m_absVisibleMaxV

double mpScaleBase::m_absVisibleMaxV
protectedinherited

◆ m_brush

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

◆ m_continuous

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

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

◆ m_drawOutsideMargins

◆ m_flags

int mpScaleY::m_flags
protectedinherited

Definition at line 997 of file mathplot.h.

Referenced by mpScaleY::Plot().

◆ m_font

◆ m_masterScale

mpScaleY* mpScaleY::m_masterScale
protectedinherited

Definition at line 993 of file mathplot.h.

Referenced by mpScaleY::computeSlaveTicks(), and mpScaleY::recalculateTicks().

◆ m_maxLabelHeight

int mpScaleBase::m_maxLabelHeight
protectedinherited

◆ m_maxLabelWidth

int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 836 of file mathplot.h.

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

◆ m_maxV

◆ m_minV

◆ m_name

wxString mpLayer::m_name
protectedinherited

◆ m_nameFlags

int mpScaleBase::m_nameFlags
protectedinherited

Definition at line 831 of file mathplot.h.

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

◆ m_offset

◆ m_pen

◆ m_rangeSet

bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 834 of file mathplot.h.

Referenced by mpScaleBase::mpScaleBase().

◆ m_scale

◆ m_showName

bool mpLayer::m_showName
protectedinherited

◆ m_tickLabels

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

◆ m_ticks

bool mpScaleY::m_ticks
protectedinherited

Definition at line 998 of file mathplot.h.

Referenced by mpScaleY::Plot().

◆ m_tickValues

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

◆ m_type

mpLayerType mpLayer::m_type
protectedinherited

Definition at line 320 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

◆ m_visible


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