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 200 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 203 of file sim_plot_panel.cpp.

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

Member Function Documentation

◆ AbsMaxValue()

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 763 of file mathplot.h.

764  {
765  return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
766  }
double m_maxV
Definition: mathplot.h:835
double m_minV
Definition: mathplot.h:835

◆ AbsVisibleMaxValue()

double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 768 of file mathplot.h.

769  {
770  return m_absVisibleMaxV;
771  }
double m_absVisibleMaxV
Definition: mathplot.h:831

◆ computeLabelExtents()

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

Definition at line 935 of file mathplot.cpp.

936 {
937  // printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
938  m_maxLabelHeight = 0;
939  m_maxLabelWidth = 0;
940 
941  for( int n = 0; n < labelCount(); n++ )
942  {
943  int tx, ty;
944  const wxString s = getLabel( n );
945 
946  dc.GetTextExtent( s, &tx, &ty );
947  m_maxLabelHeight = std::max( ty, m_maxLabelHeight );
948  m_maxLabelWidth = std::max( tx, m_maxLabelWidth );
949  }
950 }
int m_maxLabelHeight
Definition: mathplot.h:837
int m_maxLabelWidth
Definition: mathplot.h:838
virtual const wxString getLabel(int n)
Definition: mathplot.h:822
virtual int labelCount() const
Definition: mathplot.h:804

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

Referenced by mpScaleBase::updateTickLabels().

◆ ExtendDataRange()

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

Definition at line 737 of file mathplot.h.

738  {
739  if( !m_rangeSet )
740  {
741  m_minV = minV;
742  m_maxV = maxV;
743  m_rangeSet = true;
744  }
745  else
746  {
747  m_minV = std::min( minV, m_minV );
748  m_maxV = std::max( maxV, m_maxV );
749  }
750 
751  if( m_minV == m_maxV )
752  {
753  m_minV = m_minV - 1.0;
754  m_maxV = m_maxV + 1.0;
755  }
756  }
double m_maxV
Definition: mathplot.h:835
bool m_rangeSet
Definition: mathplot.h:836
double m_minV
Definition: mathplot.h:835

Referenced by mpFXY::UpdateScales().

◆ formatLabel()

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

Definition at line 809 of file mathplot.h.

809 { return wxT( "" ); }

◆ formatLabels()

void VOLTAGE_SCALE_X::formatLabels ( )
inlineoverridevirtual

Reimplemented from mpScaleBase.

Definition at line 206 of file sim_plot_panel.cpp.

207  {
208  formatSILabels( this, wxT( "V" ), 3 );
209  }
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 }
double square(double x)
wxPen m_pen
Definition: mathplot.h:314

References mpLayer::m_pen, and square().

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

732  {
733  minV = m_minV;
734  maxV = m_maxV;
735  }
double m_maxV
Definition: mathplot.h:835
double m_minV
Definition: mathplot.h:835

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

823  {
824  return m_tickLabels[n].label;
825  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:828

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

◆ getLabelPos()

virtual double mpScaleBase::getLabelPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 817 of file mathplot.h.

818  {
819  return m_tickLabels[n].pos;
820  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:828

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

813  {
814  return m_tickValues[n];
815  }
std::vector< double > m_tickValues
Definition: mathplot.h:827

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

718 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:834

Referenced by SIM_PLOT_PANEL::IsGridShown().

◆ getVisibleDataRange()

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

Reimplemented from mpScaleBase.

Definition at line 1190 of file mathplot.cpp.

1191 {
1192  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1193  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1194 
1195  // printf("getVisibleDataRange\n");
1196 
1197  double pxmin = w.p2x( startPx );
1198  double pxmax = w.p2x( endPx );
1199 
1200  minV = TransformFromPlot( pxmin );
1201  maxV = TransformFromPlot( pxmax );
1202 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1187
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1133
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Definition: mathplot.h:1368
int GetMarginLeft()
Definition: mathplot.h:1372
virtual double TransformFromPlot(double xplot)
Definition: mathplot.h:774

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

700 { return FALSE; }

◆ IsHorizontal()

virtual bool mpScaleXBase::IsHorizontal ( )
inlineoverridevirtualinherited

Implements mpScaleBase.

Definition at line 854 of file mathplot.h.

854 { 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 804 of file mathplot.h.

805  {
806  return m_tickLabels.size();
807  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:828

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

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

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

834 {
835  double minV, maxV, minVvis, maxVvis;
836 
837  GetDataRange( minV, maxV );
838  getVisibleDataRange( w, minVvis, maxVvis );
839 
840  m_absVisibleMaxV = std::max( std::abs( minVvis ), std::abs( maxVvis ) );
841 
842  // printf("minV %.10f maxV %.10f %.10f %.10f\n", minV, maxV, minVvis, maxVvis);
843 
844  m_tickValues.clear();
845  m_tickLabels.clear();
846 
847  double minErr = 1000000000000.0;
848  double bestStep = 1.0;
849 
850  for( int i = 10; i <= 20; i += 2 )
851  {
852  double curr_step = fabs( maxVvis - minVvis ) / (double) i;
853  double base = pow( 10, floor( log10( curr_step ) ) );
854 
855  // printf("base %.3f\n", base);
856 
857  double stepInt = floor( curr_step / base ) * base;
858  double err = fabs( curr_step - stepInt );
859 
860  if( err < minErr )
861  {
862  minErr = err;
863  bestStep = stepInt;
864  }
865 
866  // printf("curr_step %d %.3f %.3f best %.3f\n",i, curr_step, stepInt, bestStep);
867  }
868 
869 
870  double v = floor( minVvis / bestStep ) * bestStep;
871 
872  double zeroOffset = 100000000.0;
873  // printf("maxVVis %.3f\n", maxVvis);
874 
875  while( v < maxVvis )
876  {
877  m_tickValues.push_back( v );
878 
879  if( fabs( v ) < zeroOffset )
880  zeroOffset = fabs( v );
881 
882  // printf("tick %.3f\n", v);
883  v += bestStep;
884  }
885 
886  if( zeroOffset <= bestStep )
887  {
888  for( double& t : m_tickValues )
889  t -= zeroOffset;
890  }
891 
892  for( double t : m_tickValues )
893  {
894  m_tickLabels.emplace_back( t );
895  }
896 
897  updateTickLabels( dc, w );
898 }
virtual void getVisibleDataRange(mpWindow &w, double &minV, double &maxV) override
Definition: mathplot.cpp:1190
void GetDataRange(double &minV, double &maxV)
Definition: mathplot.h:731
void updateTickLabels(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:953
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:828
double m_absVisibleMaxV
Definition: mathplot.h:831
std::vector< double > m_tickValues
Definition: mathplot.h:827

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

◆ ResetDataRange()

void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 758 of file mathplot.h.

759  {
760  m_rangeSet = 0;
761  }
bool m_rangeSet
Definition: mathplot.h:836

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

706 { m_flags = align; };
int m_flags
Definition: mathplot.h:832

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

725  {
726  m_rangeSet = true;
727  m_minV = minV;
728  m_maxV = maxV;
729  }
double m_maxV
Definition: mathplot.h:835
bool m_rangeSet
Definition: mathplot.h:836
double m_minV
Definition: mathplot.h:835

◆ 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:60
wxString m_name
Definition: mathplot.h:316

References name.

◆ SetNameAlign()

void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 708 of file mathplot.h.

708 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:833

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

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

713 { m_ticks = enable; };
bool m_ticks
Definition: mathplot.h:834

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

800  {
801  return m_tickValues.size();
802  }
std::vector< double > m_tickValues
Definition: mathplot.h:827

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

◆ TickLabels()

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

Definition at line 788 of file mathplot.h.

788 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:828

Referenced by FREQUENCY_LOG_SCALE::formatLabels().

◆ TransformFromPlot()

double mpScaleX::TransformFromPlot ( double  xplot)
overridevirtualinherited

Reimplemented from mpScaleBase.

Definition at line 3312 of file mathplot.cpp.

3313 {
3314  return xplot / m_scale - m_offset;
3315 }
double m_offset
Definition: mathplot.h:830
double m_scale
Definition: mathplot.h:830

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

3307 {
3308  return (x + m_offset) * m_scale;
3309 }
double m_offset
Definition: mathplot.h:830
double m_scale
Definition: mathplot.h:830

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

◆ updateTickLabels()

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

Definition at line 953 of file mathplot.cpp.

954 {
955  formatLabels();
956  computeLabelExtents( dc, w );
957 
958  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
959 
960  // if ( m_tickLabels.size() <= 2)
961  // return;
962 
963  /*
964  * fixme!
965  *
966  * for ( auto &l : m_tickLabels )
967  * {
968  * double p = TransformToPlot ( l.pos );
969  *
970  * if ( !IsHorizontal() )
971  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
972  * else
973  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
974  * }
975  *
976  *
977  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
978  * {
979  * int dist_prev;
980  *
981  * for(int j = i-1; j >= 1; j--)
982  * {
983  * if( m_tickLabels[j].visible)
984  * {
985  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
986  * break;
987  * }
988  * }
989  *
990  * if (dist_prev < gap)
991  * m_tickLabels[i].visible = false;
992  * }
993  */
994 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:935
virtual void formatLabels()
Definition: mathplot.h:810

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 832 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 838 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 833 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 836 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 834 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: