KiCad PCB EDA Suite
sim_plot_panel.cpp File Reference
#include "sim_plot_colors.h"
#include "sim_plot_panel.h"
#include "sim_plot_frame.h"
#include <algorithm>
#include <limits>
#include <wx/regex.h>

Go to the source code of this file.

Classes

class  LIN_SCALE< parent >
 
class  LOG_SCALE< parent >
 

Functions

static wxString formatFloat (double x, int nDigits)
 
static void getSISuffix (double x, const wxString &unit, int &power, wxString &suffix)
 
static int countDecimalDigits (double x, int maxDigits)
 
 wxDEFINE_EVENT (EVT_SIM_CURSOR_UPDATE, wxCommandEvent)
 

Function Documentation

◆ countDecimalDigits()

static int countDecimalDigits ( double  x,
int  maxDigits 
)
static

Definition at line 103 of file sim_plot_panel.cpp.

104 {
105  if( std::isnan( x ) )
106  {
107  // avoid trying to count the decimals of NaN
108  return 0;
109  }
110 
111  int64_t k = (int)( ( x - floor( x ) ) * pow( 10.0, (double) maxDigits ) );
112  int n = 0;
113 
114  while( k && ( ( k % 10LL ) == 0LL || ( k % 10LL ) == 9LL ) )
115  {
116  k /= 10LL;
117  }
118 
119  n = 0;
120 
121  while( k != 0LL )
122  {
123  n++;
124  k /= 10LL;
125  }
126 
127  return n;
128 }

Referenced by LIN_SCALE< parent >::formatLabels(), and LOG_SCALE< parent >::formatLabels().

◆ formatFloat()

static wxString formatFloat ( double  x,
int  nDigits 
)
static

Definition at line 35 of file sim_plot_panel.cpp.

36 {
37  wxString rv, fmt;
38 
39  if( nDigits )
40  {
41  fmt.Printf( "%%.0%df", nDigits );
42  }
43  else
44  {
45  fmt = wxT( "%.0f" );
46  }
47 
48  rv.Printf( fmt, x );
49 
50  return rv;
51 }

Referenced by LIN_SCALE< parent >::formatLabels(), and LOG_SCALE< parent >::formatLabels().

◆ getSISuffix()

static void getSISuffix ( double  x,
const wxString &  unit,
int &  power,
wxString &  suffix 
)
static

Definition at line 54 of file sim_plot_panel.cpp.

55 {
56  const int n_powers = 11;
57 
58  const struct
59  {
60  double exponent;
61  char suffix;
62  } powers[] =
63  {
64  { -18, 'a' },
65  { -15, 'f' },
66  { -12, 'p' },
67  { -9, 'n' },
68  { -6, 'u' },
69  { -3, 'm' },
70  { 0, 0 },
71  { 3, 'k' },
72  { 6, 'M' },
73  { 9, 'G' },
74  { 12, 'T' },
75  { 14, 'P' }
76  };
77 
78  power = 0;
79  suffix = unit;
80 
81  if( x == 0.0 )
82  return;
83 
84  for( int i = 0; i < n_powers - 1; i++ )
85  {
86  double r_cur = pow( 10, powers[i].exponent );
87 
88  if( fabs( x ) >= r_cur && fabs( x ) < r_cur * 1000.0 )
89  {
90  power = powers[i].exponent;
91 
92  if( powers[i].suffix )
93  suffix = wxString( powers[i].suffix ) + unit;
94  else
95  suffix = unit;
96 
97  return;
98  }
99  }
100 }

Referenced by LIN_SCALE< parent >::formatLabels(), and LOG_SCALE< parent >::formatLabels().

◆ wxDEFINE_EVENT()

wxDEFINE_EVENT ( EVT_SIM_CURSOR_UPDATE  ,
wxCommandEvent   
)