KiCad PCB EDA Suite
VOLTAGE_SCALE_X Class Reference
Inheritance diagram for VOLTAGE_SCALE_X:
mpScaleX mpScaleXBase mpScaleBase mpLayer

Public Member Functions

 VOLTAGE_SCALE_X (wxString name, int flags)
 
void formatLabels () override
 
virtual double TransformToPlot (double x) override
 Layer plot handler. More...
 
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

virtual void recalculateTicks (wxDC &dc, mpWindow &w) override
 
void updateTickLabels (wxDC &dc, mpWindow &w)
 
void computeLabelExtents (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 199 of file sim_plot_panel.cpp.

Constructor & Destructor Documentation

◆ VOLTAGE_SCALE_X()

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

Definition at line 202 of file sim_plot_panel.cpp.

202  :
203  mpScaleX( name, flags, false, 0 ) {};
const char * name
Definition: DXF_plotter.cpp:61
mpScaleX(const wxString &name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
Full constructor.
Definition: mathplot.cpp:1277

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 mpScaleBase::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 949 of file mathplot.cpp.

950 {
951  // printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
952  m_maxLabelHeight = 0;
953  m_maxLabelWidth = 0;
954 
955  for( int n = 0; n < labelCount(); n++ )
956  {
957  int tx, ty;
958  const wxString s = getLabel( n );
959 
960  dc.GetTextExtent( s, &tx, &ty );
963  }
964 }
int m_maxLabelHeight
Definition: mathplot.h:835
int m_maxLabelWidth
Definition: mathplot.h:836
virtual const wxString getLabel(int n)
Definition: mathplot.h:820
#define max(a, b)
Definition: auxiliary.h:86
virtual int labelCount() const
Definition: mathplot.h:802

References mpScaleBase::getLabel(), mpScaleBase::labelCount(), mpScaleBase::m_maxLabelHeight, mpScaleBase::m_maxLabelWidth, and max.

Referenced by mpScaleBase::updateTickLabels().

◆ 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_X::formatLabels ( )
inlineoverridevirtual

Reimplemented from mpScaleBase.

Definition at line 205 of file sim_plot_panel.cpp.

206  {
207  formatSILabels( this, wxT( "V" ), 3 );
208  }
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 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 716 of file mathplot.h.

716 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:832

Referenced by SIM_PLOT_PANEL::IsGridShown().

◆ getVisibleDataRange()

void mpScaleXBase::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 1204 of file mathplot.cpp.

1205 {
1206  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1207  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1208 
1209  // printf("getVisibleDataRange\n");
1210 
1211  double pxmin = w.p2x( startPx );
1212  double pxmax = w.p2x( endPx );
1213 
1214  minV = TransformFromPlot( pxmin );
1215  maxV = TransformFromPlot( pxmax );
1216 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1185
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1131
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Definition: mathplot.h:1348
int GetMarginLeft()
Definition: mathplot.h:1352
virtual double TransformFromPlot(double xplot)
Definition: mathplot.h:772

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

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

◆ HasBBox()

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

◆ IsHorizontal()

virtual bool mpScaleXBase::IsHorizontal ( )
inlineoverridevirtualinherited

Implements mpScaleBase.

Definition at line 852 of file mathplot.h.

852 { return true; }

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

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

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

◆ recalculateTicks()

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

Reimplemented from mpScaleBase.

Definition at line 847 of file mathplot.cpp.

848 {
849  double minV, maxV, minVvis, maxVvis;
850 
851  GetDataRange( minV, maxV );
852  getVisibleDataRange( w, minVvis, maxVvis );
853 
854  m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
855 
856  // printf("minV %.10f maxV %.10f %.10f %.10f\n", minV, maxV, minVvis, maxVvis);
857 
858  m_tickValues.clear();
859  m_tickLabels.clear();
860 
861  double minErr = 1000000000000.0;
862  double bestStep = 1.0;
863 
864  for( int i = 10; i <= 20; i += 2 )
865  {
866  double curr_step = fabs( maxVvis - minVvis ) / (double) i;
867  double base = pow( 10, floor( log10( curr_step ) ) );
868 
869  // printf("base %.3f\n", base);
870 
871  double stepInt = floor( curr_step / base ) * base;
872  double err = fabs( curr_step - stepInt );
873 
874  if( err < minErr )
875  {
876  minErr = err;
877  bestStep = stepInt;
878  }
879 
880  // printf("curr_step %d %.3f %.3f best %.3f\n",i, curr_step, stepInt, bestStep);
881  }
882 
883 
884  double v = floor( minVvis / bestStep ) * bestStep;
885 
886  double zeroOffset = 100000000.0;
887  // printf("maxVVis %.3f\n", maxVvis);
888 
889  while( v < maxVvis )
890  {
891  m_tickValues.push_back( v );
892 
893  if( fabs( v ) < zeroOffset )
894  zeroOffset = fabs( v );
895 
896  // printf("tick %.3f\n", v);
897  v += bestStep;
898  }
899 
900  if( zeroOffset <= bestStep )
901  {
902  for( double& t : m_tickValues )
903  t -= zeroOffset;
904  }
905 
906  for( double t : m_tickValues )
907  {
908  m_tickLabels.push_back( TickLabel( t ) );
909  }
910 
911  updateTickLabels( dc, w );
912 }
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1204
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:729
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:967
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
size_t i
Definition: json11.cpp:597
std::vector< double > m_tickValues
Definition: mathplot.h:825

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

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

704 { m_flags = align; };
int m_flags
Definition: mathplot.h:830

◆ 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

◆ 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 mpScaleBase::SetTicks ( bool  enable)
inlineinherited

Set X axis ticks or grid.

Parameters
enable= true to plot axis ticks, false to plot grid.

Definition at line 711 of file mathplot.h.

711 { m_ticks = enable; };
bool m_ticks
Definition: mathplot.h:832

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 mpScaleX::TransformFromPlot ( double  xplot)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3279 of file mathplot.cpp.

3280 {
3281  return xplot / m_scale - m_offset;
3282 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828

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

◆ TransformToPlot()

double mpScaleX::TransformToPlot ( double  x)
overridevirtualinherited

Layer plot handler.

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

Reimplemented from mpScaleBase.

Definition at line 3273 of file mathplot.cpp.

3274 {
3275  return (x + m_offset) * m_scale;
3276 }
double m_offset
Definition: mathplot.h:828
double m_scale
Definition: mathplot.h:828

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

◆ 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 mpScaleBase::m_flags
protectedinherited

Definition at line 830 of file mathplot.h.

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

◆ m_font

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

Definition at line 832 of file mathplot.h.

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