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

Constructor & Destructor Documentation

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

References mpLayer::m_type, mpLAYER_AXIS, name, mpLayer::SetFont(), mpLayer::SetName(), and mpLayer::SetPen().

1304 {
1305  SetName( name );
1306  SetFont( (wxFont&) *wxSMALL_FONT );
1307  SetPen( (wxPen&) *wxGREY_PEN );
1308  m_flags = flags;
1309  m_ticks = ticks;
1310  // m_labelType = type;
1311  m_type = mpLAYER_AXIS;
1312 }
bool m_ticks
Definition: mathplot.h:832
int m_flags
Definition: mathplot.h:830
void SetName(wxString name)
Set layer name.
Definition: mathplot.h:266
void SetPen(wxPen pen)
Set layer pen.
Definition: mathplot.h:276
void SetFont(wxFont &font)
Set layer font.
Definition: mathplot.h:271
const char * name
Definition: DXF_plotter.cpp:61
mpLayerType m_type
Definition: mathplot.h:320
virtual mpScaleXBase::~mpScaleXBase ( )
inlinevirtual

Definition at line 850 of file mathplot.h.

850 {};

Member Function Documentation

double mpScaleBase::AbsMaxValue ( ) const
inlineinherited

Definition at line 761 of file mathplot.h.

References abs, and max.

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
double mpScaleBase::AbsVisibleMaxValue ( ) const
inlineinherited

Definition at line 766 of file mathplot.h.

Referenced by formatSILabels().

767  {
768  return m_absVisibleMaxV;
769  }
double m_absVisibleMaxV
Definition: mathplot.h:829
void mpScaleBase::computeLabelExtents ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 987 of file mathplot.cpp.

References max.

988 {
989  // printf("test: %d %d %d\n", countDecimalDigits(1.0), countDecimalDigits(1.1), countDecimalDigits(1.22231));
990  m_maxLabelHeight = 0;
991  m_maxLabelWidth = 0;
992 
993  for( int n = 0; n < labelCount(); n++ )
994  {
995  int tx, ty;
996  const wxString s = getLabel( n );
997 
998  dc.GetTextExtent( s, &tx, &ty );
1001  }
1002 }
int m_maxLabelHeight
Definition: mathplot.h:835
int m_maxLabelWidth
Definition: mathplot.h:836
virtual int labelCount() const
Definition: mathplot.h:802
virtual const wxString getLabel(int n)
Definition: mathplot.h:820
#define max(a, b)
Definition: auxiliary.h:86
void mpScaleBase::ExtendDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 735 of file mathplot.h.

References max, and min.

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
virtual const wxString mpScaleBase::formatLabel ( double  value,
int  nDigits 
)
inlineprotectedvirtualinherited

Definition at line 807 of file mathplot.h.

807 { return wxT( "" ); }
virtual void mpScaleBase::formatLabels ( )
inlineprotectedvirtualinherited
const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 305 of file mathplot.h.

305 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:315
wxBitmap mpLayer::GetColourSquare ( int  side = 16)
inherited

Get a small square bitmap filled with the colour of the pen used in the layer.

Useful to create legends or similar reference to the layers.

Parameters
sideside length in pixels
Returns
a wxBitmap filled with layer's colour

Definition at line 83 of file mathplot.cpp.

References mpLayer::m_pen.

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
bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 257 of file mathplot.h.

257 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:317
void mpScaleBase::GetDataRange ( double &  minV,
double &  maxV 
)
inlineinherited

Definition at line 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
bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 284 of file mathplot.h.

284 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 242 of file mathplot.h.

242 { return m_font; }
wxFont m_font
Definition: mathplot.h:309
virtual const wxString mpScaleBase::getLabel ( int  n)
inlineprotectedvirtualinherited

Definition at line 820 of file mathplot.h.

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

821  {
822  return m_tickLabels[n].label;
823  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
virtual double mpScaleBase::getLabelPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 815 of file mathplot.h.

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

816  {
817  return m_tickLabels[n].pos;
818  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
mpLayerType mpLayer::GetLayerType ( )
inlineinherited

Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.

Returns
An integer indicating layer type

Definition at line 293 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320
virtual double mpLayer::GetMaxX ( )
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 179 of file mathplot.h.

Referenced by mpWindow::UpdateBBox().

179 { return 1.0; }
virtual double mpLayer::GetMaxY ( )
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 189 of file mathplot.h.

Referenced by mpWindow::UpdateBBox().

189 { return 1.0; }
virtual double mpLayer::GetMinX ( )
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 174 of file mathplot.h.

Referenced by mpWindow::UpdateBBox().

174 { return -1.0; }
virtual double mpLayer::GetMinY ( )
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 184 of file mathplot.h.

Referenced by mpWindow::UpdateBBox().

184 { return -1.0; }
const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

Referenced by mpInfoLegend::Plot(), and mpText::Plot().

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316
const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314
virtual double mpScaleBase::getTickPos ( int  n)
inlineprotectedvirtualinherited

Definition at line 810 of file mathplot.h.

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

811  {
812  return m_tickValues[n];
813  }
std::vector< double > m_tickValues
Definition: mathplot.h:825
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
void mpScaleXBase::getVisibleDataRange ( mpWindow w,
double &  minV,
double &  maxV 
)
overridevirtual

Reimplemented from mpScaleBase.

Definition at line 1242 of file mathplot.cpp.

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

1243 {
1244  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1245  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1246 
1247  // printf("getVisibleDataRange\n");
1248 
1249  double pxmin = w.p2x( startPx );
1250  double pxmax = w.p2x( endPx );
1251 
1252  minV = TransformFromPlot( pxmin );
1253  maxV = TransformFromPlot( pxmax );
1254 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1185
int GetScrX(void) const
Get current view&#39;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
bool mpScaleBase::HasBBox ( )
inlineoverridevirtualinherited

Check whether this layer has a bounding box.

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

Return values
TRUEHas bounding box
FALSEHas not bounding box

Reimplemented from mpLayer.

Reimplemented in mpScaleY.

Definition at line 698 of file mathplot.h.

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

Implements mpScaleBase.

Definition at line 852 of file mathplot.h.

852 { return true; }
virtual bool mpLayer::IsInfo ( )
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns FALSE. It is overrided to TRUE for mpInfoLayer class and its derivative. It is necessary to define mouse actions behaviour over info boxes.

Returns
whether the layer is an info boxes
See also
mpInfoLayer::IsInfo

Reimplemented in mpInfoLayer.

Definition at line 169 of file mathplot.h.

169 { return false; };
bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

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

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321
virtual int mpScaleBase::labelCount ( ) const
inlineprotectedvirtualinherited

Definition at line 802 of file mathplot.h.

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

803  {
804  return m_tickLabels.size();
805  }
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
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 1327 of file mathplot.cpp.

References mpScaleBase::getLabelPos(), mpWindow::GetMarginBottom(), mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetMarginTop(), mpWindow::GetPosX(), mpWindow::GetScaleX(), mpWindow::GetScrX(), mpWindow::GetScrY(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), mpLayer::m_drawOutsideMargins, mpScaleBase::m_flags, mpLayer::m_font, mpScaleBase::m_maxLabelHeight, mpScaleBase::m_maxV, mpScaleBase::m_minV, mpLayer::m_name, mpScaleBase::m_nameFlags, mpScaleBase::m_offset, mpLayer::m_pen, mpScaleBase::m_scale, mpScaleBase::m_tickLabels, mpScaleBase::m_ticks, mpLayer::m_visible, mpALIGN_BORDER_BOTTOM, mpALIGN_BORDER_TOP, mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP, mpScaleXLog::recalculateTicks(), mpScaleBase::tickCount(), mpScaleXLog::TransformToPlot(), X_BORDER_SEPARATION, and mpWindow::y2p().

1328 {
1329  int tx, ty;
1330 
1331  m_offset = -m_minV;
1332  m_scale = 1.0 / ( m_maxV - m_minV );
1333 
1334  recalculateTicks( dc, w );
1335 
1336  if( m_visible )
1337  {
1338  dc.SetPen( m_pen );
1339  dc.SetFont( m_font );
1340  int orgy = 0;
1341 
1342  const int extend = w.GetScrX();
1343 
1344  if( m_flags == mpALIGN_CENTER )
1345  orgy = w.y2p( 0 ); // (int)(w.GetPosY() * w.GetScaleY());
1346 
1347  if( m_flags == mpALIGN_TOP )
1348  {
1349  if( m_drawOutsideMargins )
1350  orgy = X_BORDER_SEPARATION;
1351  else
1352  orgy = w.GetMarginTop();
1353  }
1354 
1355  if( m_flags == mpALIGN_BOTTOM )
1356  {
1357  if( m_drawOutsideMargins )
1358  orgy = X_BORDER_SEPARATION;
1359  else
1360  orgy = w.GetScrY() - w.GetMarginBottom();
1361  }
1362 
1364  orgy = w.GetScrY() - 1; // dc.LogicalToDeviceY(0) - 1;
1365 
1366  if( m_flags == mpALIGN_BORDER_TOP )
1367  orgy = 1; // -dc.LogicalToDeviceY(0);
1368 
1369  // dc.DrawLine( 0, orgy, w.GetScrX(), orgy);
1370 
1371  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
1372  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
1373  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
1374  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
1375 
1376  // printf("StartPx %d endPx %d ordy %d maxy %d\n", startPx, endPx, orgy, maxYpx);
1377 
1378  // int tmp=-65535;
1379  int labelH = m_maxLabelHeight; // Control labels heigth to decide where to put axis name (below labels or on top of axis)
1380 
1381  // int maxExtent = tc.MaxLabelWidth();
1382  // printf("Ticks : %d\n",labelCount());
1383  for( int n = 0; n < tickCount(); n++ )
1384  {
1385  double tp = getTickPos( n );
1386 
1387  // double xlogmin = log10 ( m_minV );
1388  // double xlogmax = log10 ( m_maxV );
1389 
1390  double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1391 
1392  const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
1393 
1394 #ifdef MATHPLOT_DO_LOGGING
1395  wxLogMessage( wxT( "mpScaleX::Plot: n: %f -> p = %d" ), n, p );
1396 #endif
1397 
1398  if( (p >= startPx) && (p <= endPx) )
1399  {
1400  if( m_ticks ) // draw axis ticks
1401  {
1403  dc.DrawLine( p, orgy, p, orgy - 4 );
1404  else
1405  dc.DrawLine( p, orgy, p, orgy + 4 );
1406  }
1407  else // draw grid dotted lines
1408  {
1409  m_pen.SetStyle( wxPENSTYLE_DOT );
1410  dc.SetPen( m_pen );
1411 
1413  {
1414  // printf("d1");
1415  m_pen.SetStyle( wxPENSTYLE_DOT );
1416  dc.SetPen( m_pen );
1417  dc.DrawLine( p, orgy + 4, p, minYpx );
1418  m_pen.SetStyle( wxPENSTYLE_SOLID );
1419  dc.SetPen( m_pen );
1420  dc.DrawLine( p, orgy + 4, p, orgy - 4 );
1421  }
1422  else
1423  {
1425  {
1426  // printf("d2");
1427  dc.DrawLine( p, orgy - 4, p, maxYpx );
1428  }
1429  else
1430  {
1431  // printf("d3");
1432  dc.DrawLine( p, minYpx, p, maxYpx ); // 0/*-w.GetScrY()*/, p, w.GetScrY() );
1433  }
1434  }
1435 
1436  m_pen.SetStyle( wxPENSTYLE_SOLID );
1437  dc.SetPen( m_pen );
1438  }
1439  }
1440  }
1441 
1442  m_pen.SetStyle( wxPENSTYLE_SOLID );
1443  dc.SetPen( m_pen );
1444  dc.DrawLine( startPx, minYpx, endPx, minYpx );
1445  dc.DrawLine( startPx, maxYpx, endPx, maxYpx );
1446 
1447  // printf("Labels : %d\n",labelCount());
1448  // Actually draw labels, taking care of not overlapping them, and distributing them regularly
1449  for( int n = 0; n < labelCount(); n++ )
1450  {
1451  double tp = getLabelPos( n );
1452 
1453  if( !m_tickLabels[n].visible )
1454  continue;
1455 
1456  // double xlogmin = log10 ( m_minV );
1457  // double xlogmax = log10 ( m_maxV );
1458 
1459  double px = TransformToPlot( tp ); // ( log10 ( tp ) - xlogmin) / (xlogmax - xlogmin);
1460 
1461  const int p = (int) ( ( px - w.GetPosX() ) * w.GetScaleX() );
1462 
1463  // printf("p %d %.1f\n", p, px);
1464 #ifdef MATHPLOT_DO_LOGGING
1465  wxLogMessage( wxT( "mpScaleX::Plot: n_label = %f -> p_label = %d" ), n, p );
1466 #endif
1467 
1468  if( (p >= startPx) && (p <= endPx) )
1469  {
1470  // Write ticks labels in s string
1471  wxString s = m_tickLabels[n].label;
1472 
1473  dc.GetTextExtent( s, &tx, &ty );
1474 
1476  {
1477  dc.DrawText( s, p - tx / 2, orgy - 4 - ty );
1478  }
1479  else
1480  {
1481  dc.DrawText( s, p - tx / 2, orgy + 4 );
1482  }
1483  }
1484  }
1485 
1486  // Draw axis name
1487  dc.GetTextExtent( m_name, &tx, &ty );
1488 
1489  switch( m_nameFlags )
1490  {
1491  case mpALIGN_BORDER_BOTTOM:
1492  dc.DrawText( m_name, extend - tx - 4, orgy - 8 - ty - labelH );
1493  break;
1494 
1495  case mpALIGN_BOTTOM:
1496  {
1497  dc.DrawText( m_name, (endPx + startPx) / 2 - tx / 2, orgy + 6 + labelH );
1498  }
1499  break;
1500 
1501  case mpALIGN_CENTER:
1502  dc.DrawText( m_name, extend - tx - 4, orgy - 4 - ty );
1503  break;
1504 
1505  case mpALIGN_TOP:
1506  {
1507  if( (!m_drawOutsideMargins) && ( w.GetMarginTop() > (ty + labelH + 8) ) )
1508  {
1509  dc.DrawText( m_name, (endPx - startPx - tx) >> 1, orgy - 6 - ty - labelH );
1510  }
1511  else
1512  {
1513  dc.DrawText( m_name, extend - tx - 4, orgy + 4 );
1514  }
1515  }
1516  break;
1517 
1518  case mpALIGN_BORDER_TOP:
1519  dc.DrawText( m_name, extend - tx - 4, orgy + 6 + labelH );
1520  break;
1521 
1522  default:
1523  break;
1524  }
1525  }
1526 }
double m_maxV
Definition: mathplot.h:833
virtual void recalculateTicks(wxDC &dc, mpWindow &w)
Definition: mathplot.h:795
bool m_ticks
Definition: mathplot.h:832
int tickCount() const
Definition: mathplot.h:797
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 GetScrY(void) const
Get current view&#39;s Y dimension in device context units.
Definition: mathplot.h:1140
bool m_visible
Definition: mathplot.h:321
#define X_BORDER_SEPARATION
Definition: mathplot.h:93
#define mpALIGN_BORDER_TOP
Aligns X axis to top border.
Definition: mathplot.h:488
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1200
int GetMarginTop()
Definition: mathplot.h:1346
virtual int labelCount() const
Definition: mathplot.h:802
double GetPosX(void) const
Definition: mathplot.h:1116
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
int GetScrX(void) const
Get current view&#39;s X dimension in device context units.
Definition: mathplot.h:1131
double m_minV
Definition: mathplot.h:833
double GetScaleX(void) const
Definition: mathplot.h:1102
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 double getTickPos(int n)
Definition: mathplot.h:810
virtual void mpScaleBase::recalculateTicks ( wxDC &  dc,
mpWindow w 
)
inlineprotectedvirtualinherited

Reimplemented in mpScaleY, mpScaleXLog, and mpScaleX.

Definition at line 795 of file mathplot.h.

795 {};
void mpScaleBase::ResetDataRange ( )
inlineinherited

Definition at line 756 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::ResetScales().

757  {
758  m_rangeSet = 0;
759  }
bool m_rangeSet
Definition: mathplot.h:834
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
void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 309 of file mathplot.h.

309 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:315
void mpLayer::SetContinuity ( bool  continuity)
inlineinherited

Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).

See also
GetContinuity

Definition at line 252 of file mathplot.h.

Referenced by TRACE::TRACE().

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317
void mpScaleBase::SetDataRange ( double  minV,
double  maxV 
)
inlineinherited

Definition at line 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
void mpLayer::SetDrawOutsideMargins ( bool  drawModeOutside)
inlineinherited

Set Draw mode: inside or outside margins.

Default is outside, which allows the layer to draw up to the mpWindow border.

Parameters
drawModeOutsideThe draw mode to be set

Definition at line 280 of file mathplot.h.

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

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 271 of file mathplot.h.

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

271 { m_font = font; }
wxFont m_font
Definition: mathplot.h:309
void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 266 of file mathplot.h.

References name.

Referenced by mpFX::mpFX(), mpFXY::mpFXY(), mpFY::mpFY(), mpProfile::mpProfile(), mpScaleXBase(), mpScaleY::mpScaleY(), and mpText::mpText().

266 { m_name = name; }
const char * name
Definition: DXF_plotter.cpp:61
wxString m_name
Definition: mathplot.h:316
void mpScaleBase::SetNameAlign ( int  align)
inlineinherited

Definition at line 706 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

706 { m_nameFlags = align; }
int m_nameFlags
Definition: mathplot.h:831
void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 276 of file mathplot.h.

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

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314
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.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

711 { m_ticks = enable; };
bool m_ticks
Definition: mathplot.h:832
void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

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

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321
void mpLayer::ShowName ( bool  show)
inlineinherited

Shows or hides the text label with the name of the layer (default is visible).

Definition at line 261 of file mathplot.h.

Referenced by TRACE::TRACE().

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318
int mpScaleBase::tickCount ( ) const
inlineprotectedinherited

Definition at line 797 of file mathplot.h.

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

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

Definition at line 786 of file mathplot.h.

Referenced by FREQUENCY_LOG_SCALE::formatLabels(), and formatSILabels().

786 { return m_tickLabels; };
std::vector< TickLabel > m_tickLabels
Definition: mathplot.h:826
virtual double mpScaleBase::TransformFromPlot ( double  xplot)
inlinevirtualinherited

Reimplemented in mpScaleY, mpScaleXLog, and mpScaleX.

Definition at line 772 of file mathplot.h.

772 { return 0.0; };
virtual double mpScaleBase::TransformToPlot ( double  x)
inlinevirtualinherited

Reimplemented in mpScaleY, mpScaleXLog, and mpScaleX.

Definition at line 771 of file mathplot.h.

771 { return 0.0; };
void mpScaleBase::updateTickLabels ( wxDC &  dc,
mpWindow w 
)
protectedinherited

Definition at line 1005 of file mathplot.cpp.

References mpScaleBase::getLabel(), mpScaleBase::getLabelPos(), mpScaleBase::getTickPos(), mpScaleBase::labelCount(), and mpScaleBase::tickCount().

1006 {
1007  formatLabels();
1008  computeLabelExtents( dc, w );
1009 
1010  // int gap = IsHorizontal() ? m_maxLabelWidth + 10 : m_maxLabelHeight + 5;
1011 
1012  // if ( m_tickLabels.size() <= 2)
1013  // return;
1014 
1015  /*
1016  * fixme!
1017  *
1018  * for ( auto &l : m_tickLabels )
1019  * {
1020  * double p = TransformToPlot ( l.pos );
1021  *
1022  * if ( !IsHorizontal() )
1023  * l.pixelPos = (int)(( w.GetPosY() - p ) * w.GetScaleY());
1024  * else
1025  * l.pixelPos = (int)(( p - w.GetPosX()) * w.GetScaleX());
1026  * }
1027  *
1028  *
1029  * for (int i = 1; i < m_tickLabels.size() - 1; i++)
1030  * {
1031  * int dist_prev;
1032  *
1033  * for(int j = i-1; j >= 1; j--)
1034  * {
1035  * if( m_tickLabels[j].visible)
1036  * {
1037  * dist_prev = abs( m_tickLabels[j].pixelPos - m_tickLabels[i].pixelPos );
1038  * break;
1039  * }
1040  * }
1041  *
1042  * if (dist_prev < gap)
1043  * m_tickLabels[i].visible = false;
1044  * }
1045  */
1046 }
void computeLabelExtents(wxDC &dc, mpWindow &w)
Definition: mathplot.cpp:987
virtual void formatLabels()
Definition: mathplot.h:808

Member Data Documentation

double mpScaleBase::m_absVisibleMaxV
protectedinherited

Definition at line 829 of file mathplot.h.

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

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

bool mpLayer::m_drawOutsideMargins
protectedinherited
int mpScaleBase::m_flags
protectedinherited

Definition at line 830 of file mathplot.h.

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

wxFont mpLayer::m_font
protectedinherited
int mpScaleBase::m_maxLabelHeight
protectedinherited

Definition at line 835 of file mathplot.h.

Referenced by Plot().

int mpScaleBase::m_maxLabelWidth
protectedinherited

Definition at line 836 of file mathplot.h.

double mpScaleBase::m_maxV
protectedinherited
double mpScaleBase::m_minV
protectedinherited
wxString mpLayer::m_name
protectedinherited

Definition at line 316 of file mathplot.h.

Referenced by mpFX::Plot(), mpFY::Plot(), mpFXY::Plot(), mpProfile::Plot(), Plot(), and mpScaleY::Plot().

int mpScaleBase::m_nameFlags
protectedinherited

Definition at line 831 of file mathplot.h.

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

double mpScaleBase::m_offset
protectedinherited
bool mpScaleBase::m_rangeSet
protectedinherited

Definition at line 834 of file mathplot.h.

double mpScaleBase::m_scale
protectedinherited
bool mpLayer::m_showName
protectedinherited

Definition at line 318 of file mathplot.h.

Referenced by mpFX::Plot(), mpFY::Plot(), and mpFXY::Plot().

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

Definition at line 826 of file mathplot.h.

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

bool mpScaleBase::m_ticks
protectedinherited

Definition at line 832 of file mathplot.h.

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

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

Definition at line 825 of file mathplot.h.


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