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>

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

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

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

◆ formatFloat()

static wxString formatFloat ( double  x,
int  nDigits 
)
static

Definition at line 36 of file sim_plot_panel.cpp.

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

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

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

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

◆ wxDEFINE_EVENT()

wxDEFINE_EVENT ( EVT_SIM_CURSOR_UPDATE  ,
wxCommandEvent   
)