KiCad PCB EDA Suite
FREQUENCY_LOG_SCALE Class Reference
Inheritance diagram for FREQUENCY_LOG_SCALE:
mpScaleXLog mpScaleXBase mpScaleBase mpLayer

Public Member Functions

 FREQUENCY_LOG_SCALE (wxString name, int flags)
 
void formatLabels () override
 
virtual double TransformToPlot (double x) override
 
virtual double TransformFromPlot (double xplot) override
 
virtual bool IsHorizontal () override
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Layer plot handler. More...
 
virtual void getVisibleDataRange (mpWindow &w, double &minV, double &maxV) override
 
bool HasBBox () override
 Check whether this layer has a bounding box. More...
 
void SetAlign (int align)
 Set X axis alignment. More...
 
void SetNameAlign (int align)
 
void SetTicks (bool enable)
 Set X axis ticks or grid. More...
 
bool GetTicks ()
 Get X axis ticks or grid. More...
 
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

void recalculateTicks (wxDC &dc, mpWindow &w) override
 Layer plot handler. More...
 
void computeLabelExtents (wxDC &dc, 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

std::vector< double > m_tickValues
 
std::vector< TickLabelm_tickLabels
 
double m_offset
 
double m_scale
 
double m_absVisibleMaxV
 
int m_flags
 
int m_nameFlags
 
bool m_ticks
 
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 148 of file sim_plot_panel.cpp.

Constructor & Destructor Documentation

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

Definition at line 151 of file sim_plot_panel.cpp.

151  :
152  mpScaleXLog( name, flags ) {};
const char * name
mpScaleXLog(wxString name=wxT("log(X)"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
Definition: mathplot.cpp:1294

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 mpScaleXLog::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protectedinherited
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( "" ); }
void FREQUENCY_LOG_SCALE::formatLabels ( )
inlineoverridevirtual

Reimplemented from mpScaleBase.

Definition at line 154 of file sim_plot_panel.cpp.

References countDecimalDigits(), formatFloat(), getSISuffix(), and mpScaleBase::TickLabels().

155  {
156  const wxString unit = wxT( "Hz" );
157  wxString suffix;
158  int power;
159 
160  for( auto &l : TickLabels() )
161  {
162  getSISuffix( l.pos, unit, power, suffix );
163  double sf = pow( 10.0, power );
164  int k = countDecimalDigits( l.pos / sf, 3 );
165 
166  l.label = formatFloat( l.pos / sf, k ) + suffix;
167  l.visible = true;
168  }
169  }
static wxString formatFloat(double x, int nDigits)
std::vector< TickLabel > & TickLabels()
Definition: mathplot.h:782
static int countDecimalDigits(double x, int maxDigits)
static void getSISuffix(double x, const wxString &unit, int &power, wxString &suffix)
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 mpScaleY::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 mpScaleY::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 mpScaleY::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 mpScaleY::Plot().

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

Get X axis ticks or grid.

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

Definition at line 712 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::IsGridShown().

712 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:828
void mpScaleXBase::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1215 of file mathplot.cpp.

References mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetScrX(), mpLayer::m_drawOutsideMargins, mpWindow::p2x(), and mpScaleBase::TransformFromPlot().

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

1216 {
1217  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1218  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1219 
1220  // printf("getVisibleDataRange\n");
1221 
1222  double pxmin = w.p2x( startPx );
1223  double pxmax = w.p2x( endPx );
1224 
1225  minV = TransformFromPlot( pxmin );
1226  maxV = TransformFromPlot( pxmax );
1227 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1181
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1127
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 double TransformFromPlot(double xplot)
Definition: mathplot.h:768
bool mpScaleBase::HasBBox ( )
inlineoverridevirtualinherited

Check whether this layer has a bounding box.

The default implementation returns TRUE. Override and return FALSE if your mpLayer implementation should be ignored by the calculation of the global bounding box for all layers in a mpWindow.

Return values
TRUEHas bounding box
FALSEHas not bounding box

Reimplemented from mpLayer.

Reimplemented in mpScaleY.

Definition at line 698 of file mathplot.h.

698 { return FALSE; }
virtual bool mpScaleXBase::IsHorizontal ( )
inlineoverridevirtualinherited

Implements mpScaleBase.

Definition at line 848 of file mathplot.h.

848 { return true; }
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 mpScaleY::Plot().

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

Layer plot handler.

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

2;

Implements mpLayer.

Definition at line 1300 of file mathplot.cpp.

References mpScaleBase::getLabelPos(), mpWindow::GetMarginBottom(), mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetMarginTop(), mpWindow::GetPosX(), mpWindow::GetScaleX(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), mpLayer::m_drawOutsideMargins, mpScaleBase::m_flags, mpLayer::m_font, mpScaleBase::m_maxLabelHeight, 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_BOTTOM, mpALIGN_BORDER_TOP, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpScaleBase::recalculateTicks(), mpScaleBase::tickCount(), mpScaleBase::TransformToPlot(), X_BORDER_SEPARATION, and mpWindow::y2p().

1301 {
1302  int tx, ty;
1303 
1304  m_offset = -m_minV;
1305  m_scale = 1.0 / ( m_maxV - m_minV );
1306 
1307  recalculateTicks( dc, w );
1308 
1309  if( m_visible )
1310  {
1311  dc.SetPen( m_pen );
1312  dc.SetFont( m_font );
1313  int orgy = 0;
1314 
1315  const int extend = w.GetScrX();
1316 
1317  if( m_flags == mpALIGN_CENTER )
1318  orgy = w.y2p( 0 ); // (int)(w.GetPosY() * w.GetScaleY());
1319 
1320  if( m_flags == mpALIGN_TOP )
1321  {
1322  if( m_drawOutsideMargins )
1323  orgy = X_BORDER_SEPARATION;
1324  else
1325  orgy = w.GetMarginTop();
1326  }
1327 
1328  if( m_flags == mpALIGN_BOTTOM )
1329  {
1330  if( m_drawOutsideMargins )
1331  orgy = X_BORDER_SEPARATION;
1332  else
1333  orgy = w.GetScrY() - w.GetMarginBottom();
1334  }
1335 
1337  orgy = w.GetScrY() - 1; // dc.LogicalToDeviceY(0) - 1;
1338 
1339  if( m_flags == mpALIGN_BORDER_TOP )
1340  orgy = 1; // -dc.LogicalToDeviceY(0);
1341 
1342  // dc.DrawLine( 0, orgy, w.GetScrX(), orgy);
1343 
1344  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1345  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1346  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1347  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1348 
1349  // printf("StartPx %d endPx %d ordy %d maxy %d\n", startPx, endPx, orgy, maxYpx);
1350 
1351  // int tmp=-65535;
1352  int labelH = m_maxLabelHeight; // Control labels heigth to decide where to put axis name (below labels or on top of axis)
1353 
1354  // int maxExtent = tc.MaxLabelWidth();
1355  // printf("Ticks : %d\n",labelCount());
1356  for( int n = 0; n < tickCount(); n++ )
1357  {
1358  double tp = getTickPos( n );
1359 
1360  // double xlogmin = log10 ( m_minV );
1361  // double xlogmax = log10 ( m_maxV );
1362 
1363  double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1364 
1365  const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
1366 
1367 #ifdef MATHPLOT_DO_LOGGING
1368  wxLogMessage( wxT( "mpScaleX::Plot: n: %f -> p = %d" ), n, p );
1369 #endif
1370 
1371  if( (p >= startPx) && (p <= endPx) )
1372  {
1373  if( m_ticks ) // draw axis ticks
1374  {
1376  dc.DrawLine( p, orgy, p, orgy - 4 );
1377  else
1378  dc.DrawLine( p, orgy, p, orgy + 4 );
1379  }
1380  else // draw grid dotted lines
1381  {
1382  m_pen.SetStyle( wxPENSTYLE_DOT );
1383  dc.SetPen( m_pen );
1384 
1386  {
1387  // printf("d1");
1388  m_pen.SetStyle( wxPENSTYLE_DOT );
1389  dc.SetPen( m_pen );
1390  dc.DrawLine( p, orgy + 4, p, minYpx );
1391  m_pen.SetStyle( wxPENSTYLE_SOLID );
1392  dc.SetPen( m_pen );
1393  dc.DrawLine( p, orgy + 4, p, orgy - 4 );
1394  }
1395  else
1396  {
1398  {
1399  // printf("d2");
1400  dc.DrawLine( p, orgy - 4, p, maxYpx );
1401  }
1402  else
1403  {
1404  // printf("d3");
1405  dc.DrawLine( p, minYpx, p, maxYpx ); // 0/*-w.GetScrY()*/, p, w.GetScrY() );
1406  }
1407  }
1408 
1409  m_pen.SetStyle( wxPENSTYLE_SOLID );
1410  dc.SetPen( m_pen );
1411  }
1412  }
1413  }
1414 
1415  m_pen.SetStyle( wxPENSTYLE_SOLID );
1416  dc.SetPen( m_pen );
1417  dc.DrawLine( startPx, minYpx, endPx, minYpx );
1418  dc.DrawLine( startPx, maxYpx, endPx, maxYpx );
1419 
1420  // printf("Labels : %d\n",labelCount());
1421  // Actually draw labels, taking care of not overlapping them, and distributing them regularly
1422  for( int n = 0; n < labelCount(); n++ )
1423  {
1424  double tp = getLabelPos( n );
1425 
1426  if( !m_tickLabels[n].visible )
1427  continue;
1428 
1429  // double xlogmin = log10 ( m_minV );
1430  // double xlogmax = log10 ( m_maxV );
1431 
1432  double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1433 
1434  const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
1435 
1436  // printf("p %d %.1f\n", p, px);
1437 #ifdef MATHPLOT_DO_LOGGING
1438  wxLogMessage( wxT( "mpScaleX::Plot: n_label = %f -> p_label = %d" ), n, p );
1439 #endif
1440 
1441  if( (p >= startPx) && (p <= endPx) )
1442  {
1443  // Write ticks labels in s string
1444  wxString s = m_tickLabels[n].label;
1445 
1446  dc.GetTextExtent( s, &tx, &ty );
1447 
1449  {
1450  dc.DrawText( s, p - tx / 2, orgy - 4 - ty );
1451  }
1452  else
1453  {
1454  dc.DrawText( s, p - tx / 2, orgy + 4 );
1455  }
1456  }
1457  }
1458 
1459  // Draw axis name
1460  dc.GetTextExtent( m_name, &tx, &ty );
1461 
1462  switch( m_nameFlags )
1463  {
1464  case mpALIGN_BORDER_BOTTOM:
1465  dc.DrawText( m_name, extend - tx - 4, orgy - 8 - ty - labelH );
1466  break;
1467 
1468  case mpALIGN_BOTTOM:
1469  {
1470  dc.DrawText( m_name, (endPx + startPx) / 2 - tx / 2, orgy + 6 + labelH );
1471  }
1472  break;
1473 
1474  case mpALIGN_CENTER:
1475  dc.DrawText( m_name, extend - tx - 4, orgy - 4 - ty );
1476  break;
1477 
1478  case mpALIGN_TOP:
1479  {
1480  if( (!m_drawOutsideMargins) && ( w.GetMarginTop() > (ty + labelH + 8) ) )
1481  {
1482  dc.DrawText( m_name, (endPx - startPx - tx) >> 1, orgy - 6 - ty - labelH );
1483  }
1484  else
1485  {
1486  dc.DrawText( m_name, extend - tx - 4, orgy + 4 );
1487  }
1488  }
1489  break;
1490 
1491  case mpALIGN_BORDER_TOP:
1492  dc.DrawText( m_name, extend - tx - 4, orgy + 6 + labelH );
1493  break;
1494 
1495  default:
1496  break;
1497  }
1498  }
1499 }
double m_maxV
Definition: mathplot.h:829
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
Definition: mathplot.h:791
bool m_ticks
Definition: mathplot.h:828
int tickCount() const
Definition: mathplot.h:793
double m_offset
Definition: mathplot.h:824
int m_maxLabelHeight
Definition: mathplot.h:831
int GetMarginBottom()
Get the bottom margin.
Definition: mathplot.h:1344
int m_flags
Definition: mathplot.h:826
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
bool m_visible
Definition: mathplot.h:321
#define X_BORDER_SEPARATION
Definition: mathplot.h:93
#define mpALIGN_BORDER_TOP
Aligns X axis to top border.
Definition: mathplot.h:488
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1196
int GetMarginTop()
Get the top margin.
Definition: mathplot.h:1340
virtual int labelCount() const
Definition: mathplot.h:798
double GetPosX(void) const
Definition: mathplot.h:1112
virtual double getLabelPos(int n)
Definition: mathplot.h:811
#define mpALIGN_TOP
Aligns label to the top.
Definition: mathplot.h:482
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 m_minV
Definition: mathplot.h:829
double GetScaleX(void) const
Definition: mathplot.h:1098
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
#define mpALIGN_BORDER_BOTTOM
Aligns X axis to bottom border.
Definition: mathplot.h:486
double m_scale
Definition: mathplot.h:824
virtual double TransformToPlot(double x)
Definition: mathplot.h:767
wxPen m_pen
Definition: mathplot.h:314
#define mpALIGN_BOTTOM
Aligns label to the bottom.
Definition: mathplot.h:484
#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
void mpScaleXLog::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
overrideprotectedvirtualinherited

Layer plot handler.

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

Reimplemented from mpScaleBase.

Definition at line 1230 of file mathplot.cpp.

References mpScaleBase::GetDataRange(), mpScaleXBase::getVisibleDataRange(), mpScaleBase::m_tickLabels, mpScaleBase::m_tickValues, and mpScaleBase::updateTickLabels().

1231 {
1232  double minV, maxV, minVvis, maxVvis;
1233 
1234  GetDataRange( minV, maxV );
1235  getVisibleDataRange( w, minVvis, maxVvis );
1236 
1237  // double decades = log( maxV / minV ) / log(10);
1238  double minDecade = pow( 10, floor( log10( minV ) ) );
1239  double maxDecade = pow( 10, ceil( log10( maxV ) ) );
1240  // printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
1241 
1242 
1243  double visibleDecades = log( maxVvis / minVvis ) / log( 10 );
1244 
1245  double d;
1246 
1247  m_tickValues.clear();
1248  m_tickLabels.clear();
1249 
1250  if( minDecade == 0.0 )
1251  return;
1252 
1253 
1254  for( d = minDecade; d<=maxDecade; d *= 10.0 )
1255  {
1256  // printf("d %.1f\n",d );
1257  m_tickLabels.push_back( TickLabel( d ) );
1258 
1259  for( double dd = d; dd < d * 10; dd += d )
1260  {
1261  if( visibleDecades < 2 )
1262  m_tickLabels.push_back( TickLabel( dd ) );
1263 
1264  m_tickValues.push_back( dd );
1265  }
1266  }
1267 
1268  updateTickLabels( dc, w );
1269 }
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1215
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:725
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:978
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:822
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 mpScaleBase::SetAlign ( int  align)
inlineinherited

Set X axis alignment.

Parameters
alignalignment (choose between mpALIGN_BORDER_BOTTOM, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpALIGN_BORDER_TOP

Definition at line 702 of file mathplot.h.

702 { m_flags = align; };
int m_flags
Definition: mathplot.h:826
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 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.

266 { m_name = name; }
const char * 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 mpScaleBase::SetTicks ( bool  enable)
inlineinherited

Set X axis ticks or grid.

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

Definition at line 708 of file mathplot.h.

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

708 { m_ticks = enable; };
bool m_ticks
Definition: mathplot.h:828
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 mpScaleY::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 formatLabels(), and formatSILabels().

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

Reimplemented from mpScaleBase.

Definition at line 3316 of file mathplot.cpp.

References mpScaleBase::m_maxV, and mpScaleBase::m_minV.

3317 {
3318  double xlogmin = log10( m_minV );
3319  double xlogmax = log10( m_maxV );
3320 
3321  return pow( 10.0, xplot * (xlogmax - xlogmin) + xlogmin );
3322 }
double m_maxV
Definition: mathplot.h:829
double m_minV
Definition: mathplot.h:829
double mpScaleXLog::TransformToPlot ( double  x)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3307 of file mathplot.cpp.

References mpScaleBase::m_maxV, and mpScaleBase::m_minV.

3308 {
3309  double xlogmin = log10( m_minV );
3310  double xlogmax = log10( m_maxV );
3311 
3312  return ( log10( x ) - xlogmin) / (xlogmax - xlogmin);
3313 }
double m_maxV
Definition: mathplot.h:829
double m_minV
Definition: mathplot.h:829
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 mpScaleY::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().

int mpScaleBase::m_flags
protectedinherited

Definition at line 826 of file mathplot.h.

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

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

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 mpScaleY::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 mpScaleBase::m_ticks
protectedinherited

Definition at line 828 of file mathplot.h.

Referenced by mpScaleY::GetTicks(), mpScaleBase::mpScaleBase(), and mpScaleXBase::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 file: