Remove unnecessary RegEx
This broke for signals using underscores. More critically, RegEx is fragile and should not be used with user input if at all possible Fixes https://gitlab.com/kicad/code/kicad/issues/9421
This commit is contained in:
parent
10ac675905
commit
82ba456567
|
@ -32,8 +32,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include <wx/regex.h>
|
|
||||||
|
|
||||||
|
|
||||||
static wxString formatFloat( double x, int nDigits )
|
static wxString formatFloat( double x, int nDigits )
|
||||||
{
|
{
|
||||||
|
@ -318,6 +316,32 @@ SIM_PLOT_PANEL::SIM_PLOT_PANEL( const wxString& aCommand, wxWindow* parent,
|
||||||
|
|
||||||
UpdatePlotColors();
|
UpdatePlotColors();
|
||||||
|
|
||||||
|
updateAxes();
|
||||||
|
|
||||||
|
// a mpInfoLegend displays le name of traces on the left top panel corner:
|
||||||
|
m_legend = new mpInfoLegend( wxRect( 0, 40, 200, 40 ), wxTRANSPARENT_BRUSH );
|
||||||
|
m_legend->SetVisible( false );
|
||||||
|
m_plotWin->AddLayer( m_legend );
|
||||||
|
|
||||||
|
m_plotWin->EnableDoubleBuffer( true );
|
||||||
|
m_plotWin->UpdateAll();
|
||||||
|
|
||||||
|
m_sizer->Add( m_plotWin, 1, wxALL | wxEXPAND, 1 );
|
||||||
|
SetSizer( m_sizer );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SIM_PLOT_PANEL::~SIM_PLOT_PANEL()
|
||||||
|
{
|
||||||
|
// ~mpWindow destroys all the added layers, so there is no need to destroy m_traces contents
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SIM_PLOT_PANEL::updateAxes()
|
||||||
|
{
|
||||||
|
if( m_axis_x )
|
||||||
|
return;
|
||||||
|
|
||||||
switch( GetType() )
|
switch( GetType() )
|
||||||
{
|
{
|
||||||
case ST_AC:
|
case ST_AC:
|
||||||
|
@ -370,34 +394,28 @@ SIM_PLOT_PANEL::SIM_PLOT_PANEL( const wxString& aCommand, wxWindow* parent,
|
||||||
m_axis_y2->SetNameAlign ( mpALIGN_RIGHT );
|
m_axis_y2->SetNameAlign ( mpALIGN_RIGHT );
|
||||||
m_plotWin->AddLayer( m_axis_y2 );
|
m_plotWin->AddLayer( m_axis_y2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// a mpInfoLegend displays le name of traces on the left top panel corner:
|
|
||||||
m_legend = new mpInfoLegend( wxRect( 0, 40, 200, 40 ), wxTRANSPARENT_BRUSH );
|
|
||||||
m_legend->SetVisible( false );
|
|
||||||
m_plotWin->AddLayer( m_legend );
|
|
||||||
|
|
||||||
m_plotWin->EnableDoubleBuffer( true );
|
|
||||||
m_plotWin->UpdateAll();
|
|
||||||
|
|
||||||
m_sizer->Add( m_plotWin, 1, wxALL | wxEXPAND, 1 );
|
|
||||||
SetSizer( m_sizer );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SIM_PLOT_PANEL::~SIM_PLOT_PANEL()
|
|
||||||
{
|
|
||||||
// ~mpWindow destroys all the added layers, so there is no need to destroy m_traces contents
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SIM_PLOT_PANEL::prepareDCAxes()
|
void SIM_PLOT_PANEL::prepareDCAxes()
|
||||||
{
|
{
|
||||||
wxRegEx simCmd( "^.dc[[:space:]]+([[:alnum:]]+\\M).*", wxRE_ADVANCED | wxRE_ICASE );
|
wxString sim_cmd = getSimCommand().Lower();
|
||||||
|
wxString rem;
|
||||||
|
|
||||||
if( simCmd.Matches( getSimCommand() ) )
|
if( sim_cmd.StartsWith( ".dc ", &rem ) )
|
||||||
{
|
{
|
||||||
switch( static_cast<char>( simCmd.GetMatch( getSimCommand().Lower(), 1 ).GetChar( 0 ) ) )
|
wxChar ch;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
ch = rem.GetChar( 0 );
|
||||||
|
}
|
||||||
|
catch( ... )
|
||||||
|
{;}
|
||||||
|
|
||||||
|
switch( ch )
|
||||||
|
{
|
||||||
|
// Make sure that we have a reliable default (even if incorrectly labeled)
|
||||||
|
default:
|
||||||
case 'v':
|
case 'v':
|
||||||
m_axis_x =
|
m_axis_x =
|
||||||
new LIN_SCALE<mpScaleX>( _( "Voltage (swept)" ), wxT( "V" ), mpALIGN_BOTTOM );
|
new LIN_SCALE<mpScaleX>( _( "Voltage (swept)" ), wxT( "V" ), mpALIGN_BOTTOM );
|
||||||
|
@ -442,7 +460,7 @@ void SIM_PLOT_PANEL::UpdatePlotColors()
|
||||||
void SIM_PLOT_PANEL::UpdateTraceStyle( TRACE* trace )
|
void SIM_PLOT_PANEL::UpdateTraceStyle( TRACE* trace )
|
||||||
{
|
{
|
||||||
int type = trace->GetType();
|
int type = trace->GetType();
|
||||||
wxPenStyle penStyle = ( ( type & SPT_AC_PHASE || type & SPT_CURRENT ) && m_dotted_cp )
|
wxPenStyle penStyle = ( ( ( type & SPT_AC_PHASE ) || ( type & SPT_CURRENT ) ) && m_dotted_cp )
|
||||||
? wxPENSTYLE_DOT
|
? wxPENSTYLE_DOT
|
||||||
: wxPENSTYLE_SOLID;
|
: wxPENSTYLE_SOLID;
|
||||||
trace->SetPen( wxPen( trace->GetTraceColour(), 2, penStyle ) );
|
trace->SetPen( wxPen( trace->GetTraceColour(), 2, penStyle ) );
|
||||||
|
@ -456,6 +474,8 @@ bool SIM_PLOT_PANEL::addTrace( const wxString& aTitle, const wxString& aName, in
|
||||||
TRACE* trace = nullptr;
|
TRACE* trace = nullptr;
|
||||||
wxString name = aTitle;
|
wxString name = aTitle;
|
||||||
|
|
||||||
|
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( name );
|
||||||
bool addedNewEntry = ( prev == m_traces.end() );
|
bool addedNewEntry = ( prev == m_traces.end() );
|
||||||
|
|
|
@ -301,6 +301,9 @@ private:
|
||||||
///< @brief Construct the plot axes for DC simulation plot.
|
///< @brief Construct the plot axes for DC simulation plot.
|
||||||
void prepareDCAxes();
|
void prepareDCAxes();
|
||||||
|
|
||||||
|
///> Create/Ensure axes are available for plotting
|
||||||
|
void updateAxes();
|
||||||
|
|
||||||
SIM_PLOT_COLORS m_colors;
|
SIM_PLOT_COLORS m_colors;
|
||||||
|
|
||||||
// Top-level plot window
|
// Top-level plot window
|
||||||
|
|
Loading…
Reference in New Issue