Apply DRC fixes to ERC.

Fixes https://gitlab.com/kicad/code/kicad/issues/11844
This commit is contained in:
Jeff Young 2022-06-27 21:06:46 -06:00
parent d5a6452934
commit 83a2f43661
4 changed files with 55 additions and 18 deletions

View File

@ -55,6 +55,11 @@
static int DEFAULT_SINGLE_COL_WIDTH = 660; static int DEFAULT_SINGLE_COL_WIDTH = 660;
static SCHEMATIC* g_lastERCSchematic = nullptr;
static bool g_lastERCRun = false;
static std::vector<wxString> g_lastERCIgnored;
DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) : DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
DIALOG_ERC_BASE( parent ), DIALOG_ERC_BASE( parent ),
PROGRESS_REPORTER_BASE( 1 ), PROGRESS_REPORTER_BASE( 1 ),
@ -64,6 +69,8 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
m_centerMarkerOnIdle( nullptr ), m_centerMarkerOnIdle( nullptr ),
m_severities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING ) m_severities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING )
{ {
m_currentSchematic = &parent->Schematic();
SetName( DIALOG_ERC_WINDOW_NAME ); // Set a window name to be able to find it SetName( DIALOG_ERC_WINDOW_NAME ); // Set a window name to be able to find it
EESCHEMA_SETTINGS* settings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ); EESCHEMA_SETTINGS* settings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
@ -80,6 +87,14 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
m_ignoredList->InsertColumn( 0, wxEmptyString, wxLIST_FORMAT_LEFT, DEFAULT_SINGLE_COL_WIDTH ); m_ignoredList->InsertColumn( 0, wxEmptyString, wxLIST_FORMAT_LEFT, DEFAULT_SINGLE_COL_WIDTH );
if( m_currentSchematic == g_lastERCSchematic )
{
m_ercRun = g_lastERCRun;
for( const wxString& str : g_lastERCIgnored )
m_ignoredList->InsertItem( m_ignoredList->GetItemCount(), str );
}
m_notebook->SetSelection( 0 ); m_notebook->SetSelection( 0 );
SetupStandardButtons( { { wxID_OK, _( "Run ERC" ) }, SetupStandardButtons( { { wxID_OK, _( "Run ERC" ) },
@ -108,6 +123,14 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) :
DIALOG_ERC::~DIALOG_ERC() DIALOG_ERC::~DIALOG_ERC()
{ {
g_lastERCSchematic = m_currentSchematic;
g_lastERCRun = m_ercRun;
g_lastERCIgnored.clear();
for( int ii = 0; ii < m_ignoredList->GetItemCount(); ++ii )
g_lastERCIgnored.push_back( m_ignoredList->GetItemText( ii ) );
EESCHEMA_SETTINGS* settings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ); EESCHEMA_SETTINGS* settings = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxASSERT( settings ); wxASSERT( settings );
@ -190,34 +213,49 @@ void DIALOG_ERC::updateDisplayedCounts()
int numWarnings = 0; int numWarnings = 0;
int numExcluded = 0; int numExcluded = 0;
int numMarkers = 0;
if( m_markerProvider ) if( m_markerProvider )
{ {
numMarkers += m_markerProvider->GetCount();
numErrors += m_markerProvider->GetCount( RPT_SEVERITY_ERROR ); numErrors += m_markerProvider->GetCount( RPT_SEVERITY_ERROR );
numWarnings += m_markerProvider->GetCount( RPT_SEVERITY_WARNING ); numWarnings += m_markerProvider->GetCount( RPT_SEVERITY_WARNING );
numExcluded += m_markerProvider->GetCount( RPT_SEVERITY_EXCLUSION ); numExcluded += m_markerProvider->GetCount( RPT_SEVERITY_EXCLUSION );
} }
bool markersOverflowed = false;
// We don't currently have a limit on ERC violations, so the above is always false.
wxString num;
wxString msg; wxString msg;
if( m_ercRun && m_markerProvider && m_ignoredList ) if( m_ercRun )
{ {
msg.sprintf( m_violationsTitleTemplate, m_markerProvider->GetCount() ); num.Printf( markersOverflowed ? wxT( "%d+" ) : wxT( "%d" ), numMarkers );
m_notebook->SetPageText( 0, msg ); msg.Printf( m_violationsTitleTemplate, num );
msg.sprintf( m_ignoredTitleTemplate, m_ignoredList->GetItemCount() );
m_notebook->SetPageText( 1, msg );
} }
else else
{ {
msg = m_violationsTitleTemplate; msg = m_violationsTitleTemplate;
msg.Replace( wxT( "(%d)" ), wxEmptyString ); msg.Replace( wxT( "(%s)" ), wxEmptyString );
m_notebook->SetPageText( 0, msg );
msg = m_ignoredTitleTemplate;
msg.Replace( wxT( "(%d)" ), wxEmptyString );
m_notebook->SetPageText( 1, msg );
} }
m_notebook->SetPageText( 0, msg );
if( m_ercRun )
{
num.Printf( wxT( "%d" ), m_ignoredList->GetItemCount() );
msg.sprintf( m_ignoredTitleTemplate, num );
}
else
{
msg = m_ignoredTitleTemplate;
msg.Replace( wxT( "(%s)" ), wxEmptyString );
}
m_notebook->SetPageText( 1, msg );
if( !m_ercRun && numErrors == 0 ) if( !m_ercRun && numErrors == 0 )
numErrors = -1; numErrors = -1;
@ -275,8 +313,6 @@ void DIALOG_ERC::OnDeleteAllClick( wxCommandEvent& event )
// redraw the schematic // redraw the schematic
redrawDrawPanel(); redrawDrawPanel();
m_ercRun = false;
updateDisplayedCounts(); updateDisplayedCounts();
} }

View File

@ -97,6 +97,7 @@ private:
private: private:
SCH_EDIT_FRAME* m_parent; SCH_EDIT_FRAME* m_parent;
SCHEMATIC* m_currentSchematic;
wxString m_violationsTitleTemplate; wxString m_violationsTitleTemplate;
wxString m_ignoredTitleTemplate; wxString m_ignoredTitleTemplate;

View File

@ -84,7 +84,7 @@ DIALOG_ERC_BASE::DIALOG_ERC_BASE( wxWindow* parent, wxWindowID id, const wxStrin
violationsPanel->SetSizer( bViolationsSizer ); violationsPanel->SetSizer( bViolationsSizer );
violationsPanel->Layout(); violationsPanel->Layout();
bViolationsSizer->Fit( violationsPanel ); bViolationsSizer->Fit( violationsPanel );
m_notebook->AddPage( violationsPanel, _("Violations (%d)"), false ); m_notebook->AddPage( violationsPanel, _("Violations (%s)"), false );
m_panelIgnored = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_panelIgnored = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
wxBoxSizer* bSizer15; wxBoxSizer* bSizer15;
bSizer15 = new wxBoxSizer( wxVERTICAL ); bSizer15 = new wxBoxSizer( wxVERTICAL );
@ -96,7 +96,7 @@ DIALOG_ERC_BASE::DIALOG_ERC_BASE( wxWindow* parent, wxWindowID id, const wxStrin
m_panelIgnored->SetSizer( bSizer15 ); m_panelIgnored->SetSizer( bSizer15 );
m_panelIgnored->Layout(); m_panelIgnored->Layout();
bSizer15->Fit( m_panelIgnored ); bSizer15->Fit( m_panelIgnored );
m_notebook->AddPage( m_panelIgnored, _("Ignored Tests (%d)"), false ); m_notebook->AddPage( m_panelIgnored, _("Ignored Tests (%s)"), false );
bSizer13->Add( m_notebook, 1, wxEXPAND, 5 ); bSizer13->Add( m_notebook, 1, wxEXPAND, 5 );

View File

@ -619,7 +619,7 @@
<property name="window_style"></property> <property name="window_style"></property>
<object class="notebookpage" expanded="1"> <object class="notebookpage" expanded="1">
<property name="bitmap"></property> <property name="bitmap"></property>
<property name="label">Violations (%d)</property> <property name="label">Violations (%s)</property>
<property name="select">0</property> <property name="select">0</property>
<object class="wxPanel" expanded="1"> <object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>
@ -712,7 +712,7 @@
</object> </object>
<object class="notebookpage" expanded="1"> <object class="notebookpage" expanded="1">
<property name="bitmap"></property> <property name="bitmap"></property>
<property name="label">Ignored Tests (%d)</property> <property name="label">Ignored Tests (%s)</property>
<property name="select">0</property> <property name="select">0</property>
<object class="wxPanel" expanded="1"> <object class="wxPanel" expanded="1">
<property name="BottomDockable">1</property> <property name="BottomDockable">1</property>