KiCad PCB EDA Suite
mpScaleXBase Class Reference

#include <mathplot.h>

Inheritance diagram for mpScaleXBase:
mpScaleBase mpLayer mpScaleX mpScaleXLog FREQUENCY_LIN_SCALE TIME_SCALE VOLTAGE_SCALE_X FREQUENCY_LOG_SCALE

Public Member Functions

 mpScaleXBase (const wxString &name=wxT("X"), int flags=mpALIGN_CENTER, bool ticks=true, unsigned int type=mpX_NORMAL)
 Full constructor. More...
 
virtual ~mpScaleXBase ()
 
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
 
virtual double TransformToPlot (double x)
 
virtual double TransformFromPlot (double xplot)
 
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 updateTickLabels (wxDC &dc, mpWindow &w)
 
void computeLabelExtents (wxDC &dc, mpWindow &w)
 
virtual void recalculateTicks (wxDC &dc, mpWindow &w)
 
int tickCount () const
 
virtual int labelCount () const
 
virtual const wxString formatLabel (double value, int nDigits)
 
virtual void formatLabels ()
 
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 843 of file mathplot.h.

Constructor & Destructor Documentation

◆ mpScaleXBase()

mpScaleXBase::mpScaleXBase ( const wxString &  name = wxT("X"),
int  flags = mpALIGN_CENTER,
bool  ticks = true,
unsigned int  type = mpX_NORMAL 
)

Full constructor.

Parameters
nameLabel to plot by the ruler
flagsSet the position of the scale with respect to the window.
ticksSelect ticks or grid. Give TRUE (default) for drawing axis ticks, FALSE for drawing the grid.
typempX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.

Definition at line 1284 of file mathplot.cpp.

1285 {
1286  SetName( name );
1287  SetFont( (wxFont&) *wxSMALL_FONT );
1288  SetPen( (wxPen&) *wxGREY_PEN );
1289  m_flags = flags;
1290  m_ticks = ticks;
1291  // m_labelType = type;
1292  m_type = mpLAYER_AXIS;
1293 }
bool m_ticks
Definition: mathplot.h:836
int m_flags
Definition: mathplot.h:834
void SetName(wxString name)
Set layer name.
Definition: mathplot.h:268
void SetPen(wxPen pen)
Set layer pen.
Definition: mathplot.h:278
void SetFont(wxFont &font)
Set layer font.
Definition: mathplot.h:273
const char * name
Definition: DXF_plotter.cpp:60
mpLayerType m_type
Definition: mathplot.h:322

References mpLAYER_AXIS, and name.

◆ ~mpScaleXBase()

virtual mpScaleXBase::~mpScaleXBase ( )
inlinevirtual

Definition at line 854 of file mathplot.h.

854 {};

Member Function Documentation

◆ AbsMaxValue()

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 765 of file mathplot.h.

766  {
767  return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
768  }
double m_maxV
Definition: mathplot.h:837
double m_minV
Definition: mathplot.h:837

◆ AbsVisibleMaxValue()

double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 770 of file mathplot.h.

771  {
772  return m_absVisibleMaxV;
773  }
double m_absVisibleMaxV
Definition: mathplot.h:833

◆ computeLabelExtents()

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

Definition at line 968 of file mathplot.cpp.

969 {
970  // printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
971  m_maxLabelHeight = 0;
972  m_maxLabelWidth = 0;
973 
974  for( int n = 0; n < labelCount(); n++ )
975  {
976  int tx, ty;
977  const wxString s = getLabel( n );
978 
979  dc.GetTextExtent( s, &tx, &ty );
980  m_maxLabelHeight = std::max( ty, m_maxLabelHeight );
981  m_maxLabelWidth = std::max( tx, m_maxLabelWidth );
982  }
983 }
int m_maxLabelHeight
Definition: mathplot.h:839
int m_maxLabelWidth
Definition: mathplot.h:840
virtual const wxString getLabel(int n)
Definition: mathplot.h:824
virtual int labelCount() const
Definition: mathplot.h:806

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

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

Referenced by mpFXY::UpdateScales().

◆ formatLabel()

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

Definition at line 811 of file mathplot.h.

811 { return wxT( "" ); }

◆ formatLabels()

virtual void mpScaleBase::formatLabels ( )
inlineprotectedvirtualinherited

◆ GetBrush()

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 307 of file mathplot.h.

307 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:317

◆ 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:316

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

259 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:319

◆ GetDataRange()

void mpScaleBase::GetDataRange ( double &  minV,
double &  maxV 
)
inlineinherited

Definition at line 733 of file mathplot.h.

734  {
735  minV = m_minV;
736  maxV = m_maxV;
737  }
double m_maxV
Definition: mathplot.h:837
double m_minV
Definition: mathplot.h:837

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

286 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:321

◆ GetFont()

const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 244 of file mathplot.h.

244 { return m_font; }
wxFont m_font
Definition: mathplot.h:311

◆ getLabel()

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

Definition at line 824 of file mathplot.h.

825  {
826  return m_tickLabels[n].label;
827  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:830

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

◆ getLabelPos()

virtual double mpScaleBase::getLabelPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 819 of file mathplot.h.

820  {
821  return m_tickLabels[n].pos;
822  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:830

Referenced by 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 295 of file mathplot.h.

295 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:322

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

181 { 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 191 of file mathplot.h.

191 { 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 176 of file mathplot.h.

176 { 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 186 of file mathplot.h.

186 { 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 239 of file mathplot.h.

239 { return m_name; }
wxString m_name
Definition: mathplot.h:318

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

249 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:316

Referenced by mpInfoLegend::Plot().

◆ getTickPos()

virtual double mpScaleBase::getTickPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 814 of file mathplot.h.

815  {
816  return m_tickValues[n];
817  }
std::vector< double > m_tickValues
Definition: mathplot.h:829

Referenced by 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 720 of file mathplot.h.

720 { return m_ticks; };
bool m_ticks
Definition: mathplot.h:836

Referenced by SIM_PLOT_PANEL::IsGridShown().

◆ getVisibleDataRange()

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

Reimplemented from mpScaleBase.

Definition at line 1223 of file mathplot.cpp.

1224 {
1225  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1226  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1227 
1228  // printf("getVisibleDataRange\n");
1229 
1230  double pxmin = w.p2x( startPx );
1231  double pxmax = w.p2x( endPx );
1232 
1233  minV = TransformFromPlot( pxmin );
1234  maxV = TransformFromPlot( pxmax );
1235 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1189
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1135
bool m_drawOutsideMargins
Definition: mathplot.h:321
int GetMarginRight()
Definition: mathplot.h:1370
int GetMarginLeft()
Definition: mathplot.h:1374
virtual double TransformFromPlot(double xplot)
Definition: mathplot.h:776

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

702 { return FALSE; }

◆ IsHorizontal()

virtual bool mpScaleXBase::IsHorizontal ( )
inlineoverridevirtual

Implements mpScaleBase.

Definition at line 856 of file mathplot.h.

856 { 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 171 of file mathplot.h.

171 { return false; };

◆ IsVisible()

bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 299 of file mathplot.h.

299 { return m_visible; };
bool m_visible
Definition: mathplot.h:323

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

◆ labelCount()

virtual int mpScaleBase::labelCount ( ) const
inlineprotectedvirtualinherited

Definition at line 806 of file mathplot.h.

807  {
808  return m_tickLabels.size();
809  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:830

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

◆ Plot()

void mpScaleXBase::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtual

Layer plot handler.

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

2;

Implements mpLayer.

Definition at line 1308 of file mathplot.cpp.

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

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

virtual void mpScaleBase::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
inlineprotectedvirtualinherited

Reimplemented in mpScaleY, mpScaleXLog, and mpScaleX.

Definition at line 799 of file mathplot.h.

799 {};

Referenced by Plot().

◆ ResetDataRange()

void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 760 of file mathplot.h.

761  {
762  m_rangeSet = 0;
763  }
bool m_rangeSet
Definition: mathplot.h:838

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

708 { m_flags = align; };
int m_flags
Definition: mathplot.h:834

◆ SetBrush()

void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 311 of file mathplot.h.

311 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:317

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

254 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:319

Referenced by TRACE::TRACE().

◆ SetDataRange()

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

Definition at line 726 of file mathplot.h.

727  {
728  m_rangeSet = true;
729  m_minV = minV;
730  m_maxV = maxV;
731  }
double m_maxV
Definition: mathplot.h:837
bool m_rangeSet
Definition: mathplot.h:838
double m_minV
Definition: mathplot.h:837

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

282 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:321

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

273 { m_font = font; }
wxFont m_font
Definition: mathplot.h:311

◆ SetName()

void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 268 of file mathplot.h.

268 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:60
wxString m_name
Definition: mathplot.h:318

References name.

◆ SetNameAlign()

void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 710 of file mathplot.h.

710 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:835

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

278 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:316

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

715 { m_ticks = enable; };
bool m_ticks
Definition: mathplot.h:836

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

303 { m_visible = show; };
bool m_visible
Definition: mathplot.h:323

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

263 { m_showName = show; };
bool m_showName
Definition: mathplot.h:320

Referenced by TRACE::TRACE().

◆ tickCount()

int mpScaleBase::tickCount ( ) const
inlineprotectedinherited

Definition at line 801 of file mathplot.h.

802  {
803  return m_tickValues.size();
804  }
std::vector< double > m_tickValues
Definition: mathplot.h:829

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

◆ TickLabels()

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

Definition at line 790 of file mathplot.h.

790 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:830

Referenced by FREQUENCY_LOG_SCALE::formatLabels().

◆ TransformFromPlot()

virtual double mpScaleBase::TransformFromPlot ( double  xplot)
inlinevirtualinherited

Reimplemented in mpScaleY, mpScaleXLog, and mpScaleX.

Definition at line 776 of file mathplot.h.

776 { return 0.0; };

Referenced by getVisibleDataRange(), mpFXY::s2x(), and mpFXY::s2y().

◆ TransformToPlot()

virtual double mpScaleBase::TransformToPlot ( double  x)
inlinevirtualinherited

Reimplemented in mpScaleY, mpScaleXLog, and mpScaleX.

Definition at line 775 of file mathplot.h.

775 { return 0.0; };

Referenced by mpFXY::Plot(), Plot(), mpFXY::x2s(), and mpFXY::y2s().

◆ updateTickLabels()

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

Definition at line 986 of file mathplot.cpp.

987 {
988  formatLabels();
989  computeLabelExtents( dc, w );
990 
991  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
992 
993  // if ( m_tickLabels.size() <= 2)
994  // return;
995 
996  /*
997  * fixme!
998  *
999  * for ( auto &l : m_tickLabels )
1000  * {
1001  * double p = TransformToPlot ( l.pos );
1002  *
1003  * if ( !IsHorizontal() )
1004  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
1005  * else
1006  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
1007  * }
1008  *
1009  *
1010  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
1011  * {
1012  * int dist_prev;
1013  *
1014  * for(int j = i-1; j >= 1; j--)
1015  * {
1016  * if( m_tickLabels[j].visible)
1017  * {
1018  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
1019  * break;
1020  * }
1021  * }
1022  *
1023  * if (dist_prev < gap)
1024  * m_tickLabels[i].visible = false;
1025  * }
1026  */
1027 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:968
virtual void formatLabels()
Definition: mathplot.h:812

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

◆ m_continuous

bool mpLayer::m_continuous
protectedinherited

Definition at line 319 of file mathplot.h.

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

◆ m_drawOutsideMargins

bool mpLayer::m_drawOutsideMargins
protectedinherited

◆ m_flags

int mpScaleBase::m_flags
protectedinherited

Definition at line 834 of file mathplot.h.

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

◆ m_font

◆ m_maxLabelHeight

int mpScaleBase::m_maxLabelHeight
protectedinherited

Definition at line 839 of file mathplot.h.

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

◆ m_maxLabelWidth

int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 840 of file mathplot.h.

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

◆ m_maxV

double mpScaleBase::m_maxV
protectedinherited

◆ m_minV

double mpScaleBase::m_minV
protectedinherited

◆ m_name

wxString mpLayer::m_name
protectedinherited

◆ m_nameFlags

int mpScaleBase::m_nameFlags
protectedinherited

Definition at line 835 of file mathplot.h.

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

◆ m_offset

◆ m_pen

◆ m_rangeSet

bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 838 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 836 of file mathplot.h.

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

◆ m_tickValues

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

◆ m_type

mpLayerType mpLayer::m_type
protectedinherited

Definition at line 322 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

◆ m_visible


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