Coding standards & formatting.
This commit is contained in:
parent
12f464565f
commit
b2498f5673
|
@ -38,13 +38,9 @@ static wxString formatFloat( double x, int nDigits )
|
||||||
wxString rv, fmt;
|
wxString rv, fmt;
|
||||||
|
|
||||||
if( nDigits )
|
if( nDigits )
|
||||||
{
|
|
||||||
fmt.Printf( "%%.0%df", nDigits );
|
fmt.Printf( "%%.0%df", nDigits );
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
fmt = wxT( "%.0f" );
|
fmt = wxT( "%.0f" );
|
||||||
}
|
|
||||||
|
|
||||||
rv.Printf( fmt, x );
|
rv.Printf( fmt, x );
|
||||||
|
|
||||||
|
@ -58,7 +54,7 @@ static void getSISuffix( double x, const wxString& unit, int& power, wxString& s
|
||||||
|
|
||||||
const struct
|
const struct
|
||||||
{
|
{
|
||||||
double exponent;
|
int exponent;
|
||||||
char suffix;
|
char suffix;
|
||||||
} powers[] =
|
} powers[] =
|
||||||
{
|
{
|
||||||
|
@ -133,28 +129,32 @@ template <typename parent>
|
||||||
class LIN_SCALE : public parent
|
class LIN_SCALE : public parent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LIN_SCALE( wxString name, wxString unit, int flags ) : parent( name, flags ), m_unit( unit ){};
|
LIN_SCALE( const wxString& name, const wxString& unit, int flags ) :
|
||||||
|
parent( name, flags ),
|
||||||
|
m_unit( unit )
|
||||||
|
{};
|
||||||
|
|
||||||
void formatLabels() override
|
void formatLabels() override
|
||||||
{
|
{
|
||||||
double maxVis = parent::AbsVisibleMaxValue();
|
double maxVis = parent::AbsVisibleMaxValue();
|
||||||
|
|
||||||
wxString suffix;
|
wxString suffix;
|
||||||
int power, digits = 0;
|
int power = 0;
|
||||||
|
int digits = 0;
|
||||||
int constexpr DIGITS = 3;
|
int constexpr DIGITS = 3;
|
||||||
|
|
||||||
getSISuffix( maxVis, m_unit, power, suffix );
|
getSISuffix( maxVis, m_unit, power, suffix );
|
||||||
|
|
||||||
double sf = pow( 10.0, power );
|
double sf = pow( 10.0, power );
|
||||||
|
|
||||||
for( auto& l : parent::TickLabels() )
|
for( mpScaleBase::TickLabel& l : parent::TickLabels() )
|
||||||
{
|
{
|
||||||
int k = countDecimalDigits( l.pos / sf, DIGITS );
|
int k = countDecimalDigits( l.pos / sf, DIGITS );
|
||||||
|
|
||||||
digits = std::max( digits, k );
|
digits = std::max( digits, k );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( auto& l : parent::TickLabels() )
|
for( mpScaleBase::TickLabel& l : parent::TickLabels() )
|
||||||
{
|
{
|
||||||
l.label = formatFloat( l.pos / sf, digits ) + suffix;
|
l.label = formatFloat( l.pos / sf, digits ) + suffix;
|
||||||
l.visible = true;
|
l.visible = true;
|
||||||
|
@ -170,14 +170,17 @@ template <typename parent>
|
||||||
class LOG_SCALE : public parent
|
class LOG_SCALE : public parent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LOG_SCALE( wxString name, wxString unit, int flags ) : parent( name, flags ), m_unit( unit ){};
|
LOG_SCALE( const wxString& name, const wxString& unit, int flags ) :
|
||||||
|
parent( name, flags ),
|
||||||
|
m_unit( unit )
|
||||||
|
{};
|
||||||
|
|
||||||
void formatLabels() override
|
void formatLabels() override
|
||||||
{
|
{
|
||||||
wxString suffix;
|
wxString suffix;
|
||||||
int power;
|
int power;
|
||||||
|
|
||||||
for( auto& l : parent::TickLabels() )
|
for( mpScaleBase::TickLabel& l : parent::TickLabels() )
|
||||||
{
|
{
|
||||||
getSISuffix( l.pos, m_unit, power, suffix );
|
getSISuffix( l.pos, m_unit, power, suffix );
|
||||||
double sf = pow( 10.0, power );
|
double sf = pow( 10.0, power );
|
||||||
|
@ -347,8 +350,7 @@ void SIM_PLOT_PANEL::updateAxes()
|
||||||
case ST_AC:
|
case ST_AC:
|
||||||
m_axis_x = new LOG_SCALE<mpScaleXLog>( _( "Frequency" ), wxT( "Hz" ), mpALIGN_BOTTOM );
|
m_axis_x = new LOG_SCALE<mpScaleXLog>( _( "Frequency" ), wxT( "Hz" ), mpALIGN_BOTTOM );
|
||||||
m_axis_y1 = new LIN_SCALE<mpScaleY>( _( "Gain" ), wxT( "dBV" ), mpALIGN_LEFT );
|
m_axis_y1 = new LIN_SCALE<mpScaleY>( _( "Gain" ), wxT( "dBV" ), mpALIGN_LEFT );
|
||||||
m_axis_y2 = new LIN_SCALE<mpScaleY>( _( "Phase" ), wxT( "\u00B0" ),
|
m_axis_y2 = new LIN_SCALE<mpScaleY>( _( "Phase" ), wxT( "°" ), mpALIGN_RIGHT );
|
||||||
mpALIGN_RIGHT ); // degree sign
|
|
||||||
m_axis_y2->SetMasterScale( m_axis_y1 );
|
m_axis_y2->SetMasterScale( m_axis_y1 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -419,19 +421,19 @@ void SIM_PLOT_PANEL::prepareDCAxes()
|
||||||
// Make sure that we have a reliable default (even if incorrectly labeled)
|
// Make sure that we have a reliable default (even if incorrectly labeled)
|
||||||
default:
|
default:
|
||||||
case 'v':
|
case 'v':
|
||||||
m_axis_x =
|
m_axis_x = new LIN_SCALE<mpScaleX>( _( "Voltage (swept)" ), wxT( "V" ),
|
||||||
new LIN_SCALE<mpScaleX>( _( "Voltage (swept)" ), wxT( "V" ), mpALIGN_BOTTOM );
|
mpALIGN_BOTTOM );
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
m_axis_x =
|
m_axis_x = new LIN_SCALE<mpScaleX>( _( "Current (swept)" ), wxT( "A" ),
|
||||||
new LIN_SCALE<mpScaleX>( _( "Current (swept)" ), wxT( "A" ), mpALIGN_BOTTOM );
|
mpALIGN_BOTTOM );
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
m_axis_x = new LIN_SCALE<mpScaleX>( _( "Resistance (swept)" ), wxT( "\u03A9" ),
|
m_axis_x = new LIN_SCALE<mpScaleX>( _( "Resistance (swept)" ), wxT( "Ω" ),
|
||||||
mpALIGN_BOTTOM );
|
mpALIGN_BOTTOM );
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
m_axis_x = new LIN_SCALE<mpScaleX>( _( "Temperature (swept)" ), wxT( "\u00B0C" ),
|
m_axis_x = new LIN_SCALE<mpScaleX>( _( "Temperature (swept)" ), wxT( "°C" ),
|
||||||
mpALIGN_BOTTOM );
|
mpALIGN_BOTTOM );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -450,10 +452,11 @@ void SIM_PLOT_PANEL::UpdatePlotColors()
|
||||||
m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::AXIS ) );
|
m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::AXIS ) );
|
||||||
|
|
||||||
// Update color of all traces
|
// Update color of all traces
|
||||||
for( auto& t : m_traces )
|
for( auto& [ name, trace ] : m_traces )
|
||||||
if( t.second->GetCursor() )
|
{
|
||||||
t.second->GetCursor()->SetPen(
|
if( CURSOR* cursor = trace->GetCursor() )
|
||||||
wxPen( m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::CURSOR ) ) );
|
cursor->SetPen( wxPen( m_colors.GetPlotColor( SIM_PLOT_COLORS::COLOR_SET::CURSOR ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
m_plotWin->UpdateAll();
|
m_plotWin->UpdateAll();
|
||||||
}
|
}
|
||||||
|
@ -473,12 +476,11 @@ bool SIM_PLOT_PANEL::addTrace( const wxString& aTitle, const wxString& aName, in
|
||||||
const double* aX, const double* aY, SIM_PLOT_TYPE aType )
|
const double* aX, const double* aY, SIM_PLOT_TYPE aType )
|
||||||
{
|
{
|
||||||
TRACE* trace = nullptr;
|
TRACE* trace = nullptr;
|
||||||
wxString name = aTitle;
|
|
||||||
|
|
||||||
updateAxes();
|
updateAxes();
|
||||||
|
|
||||||
// Find previous entry, if there is one
|
// Find previous entry, if there is one
|
||||||
auto prev = m_traces.find( name );
|
auto prev = m_traces.find( aTitle );
|
||||||
bool addedNewEntry = ( prev == m_traces.end() );
|
bool addedNewEntry = ( prev == m_traces.end() );
|
||||||
|
|
||||||
if( addedNewEntry )
|
if( addedNewEntry )
|
||||||
|
@ -506,7 +508,7 @@ bool SIM_PLOT_PANEL::addTrace( const wxString& aTitle, const wxString& aName, in
|
||||||
trace = new TRACE( aName, aType );
|
trace = new TRACE( aName, aType );
|
||||||
trace->SetTraceColour( m_colors.GenerateColor( m_traces ) );
|
trace->SetTraceColour( m_colors.GenerateColor( m_traces ) );
|
||||||
UpdateTraceStyle( trace );
|
UpdateTraceStyle( trace );
|
||||||
m_traces[name] = trace;
|
m_traces[ aTitle ] = trace;
|
||||||
|
|
||||||
// It is a trick to keep legend & coords always on the top
|
// It is a trick to keep legend & coords always on the top
|
||||||
for( mpLayer* l : m_topLevel )
|
for( mpLayer* l : m_topLevel )
|
||||||
|
@ -577,25 +579,6 @@ bool SIM_PLOT_PANEL::deleteTrace( const wxString& aName )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SIM_PLOT_PANEL::deleteAllTraces()
|
|
||||||
{
|
|
||||||
for( auto& t : m_traces )
|
|
||||||
{
|
|
||||||
deleteTrace( t.first );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_traces.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SIM_PLOT_PANEL::HasCursorEnabled( const wxString& aName ) const
|
|
||||||
{
|
|
||||||
TRACE* t = GetTrace( aName );
|
|
||||||
|
|
||||||
return t ? t->HasCursor() : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SIM_PLOT_PANEL::EnableCursor( const wxString& aName, bool aEnable )
|
void SIM_PLOT_PANEL::EnableCursor( const wxString& aName, bool aEnable )
|
||||||
{
|
{
|
||||||
TRACE* t = GetTrace( aName );
|
TRACE* t = GetTrace( aName );
|
||||||
|
@ -638,8 +621,8 @@ void SIM_PLOT_PANEL::ResetScales()
|
||||||
if( m_axis_y2 )
|
if( m_axis_y2 )
|
||||||
m_axis_y2->ResetDataRange();
|
m_axis_y2->ResetDataRange();
|
||||||
|
|
||||||
for( auto& t : m_traces )
|
for( auto& [ name, trace ] : m_traces )
|
||||||
t.second->UpdateScales();
|
trace->UpdateScales();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -268,9 +268,6 @@ public:
|
||||||
return m_dotted_cp;
|
return m_dotted_cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
///< Returns true if the trace has cursor shown.
|
|
||||||
bool HasCursorEnabled( const wxString& aName ) const;
|
|
||||||
|
|
||||||
///< Toggle cursor for a particular trace.
|
///< Toggle cursor for a particular trace.
|
||||||
void EnableCursor( const wxString& aName, bool aEnable );
|
void EnableCursor( const wxString& aName, bool aEnable );
|
||||||
|
|
||||||
|
@ -295,8 +292,6 @@ protected:
|
||||||
|
|
||||||
bool deleteTrace( const wxString& aName );
|
bool deleteTrace( const wxString& aName );
|
||||||
|
|
||||||
void deleteAllTraces();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///< @brief Construct the plot axes for DC simulation plot.
|
///< @brief Construct the plot axes for DC simulation plot.
|
||||||
void prepareDCAxes();
|
void prepareDCAxes();
|
||||||
|
|
Loading…
Reference in New Issue