Allow ERC/DRC markers to be deleted without deleting exclusions.

Fixes https://gitlab.com/kicad/code/kicad/issues/4953
This commit is contained in:
Jeff Young 2020-08-02 22:45:06 +01:00
parent 16c645bfd9
commit c56599ab07
12 changed files with 88 additions and 85 deletions

View File

@ -387,18 +387,30 @@ void RC_TREE_MODEL::ValueChanged( RC_TREE_NODE* aNode )
void RC_TREE_MODEL::DeleteCurrentItem( bool aDeep )
{
RC_TREE_NODE* tree_node = ToNode( m_view->GetCurrentItem() );
const RC_ITEM* drc_item = tree_node ? tree_node->m_RcItem : nullptr;
DeleteItems( true, false, false, aDeep );
}
if( !drc_item )
void RC_TREE_MODEL::DeleteItems( bool aCurrent, bool aWarningsAndErrors, bool aExclusions,
bool aDeep )
{
RC_TREE_NODE* current_node = ToNode( m_view->GetCurrentItem() );
const RC_ITEM* current_item = current_node ? current_node->m_RcItem : nullptr;
if( !current_item && !aWarningsAndErrors && !aExclusions )
{
wxBell();
return;
}
for( int i = 0; i < m_rcItemsProvider->GetCount(); ++i )
for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
{
if( m_rcItemsProvider->GetItem( i ) == drc_item )
RC_ITEM* rcItem = m_rcItemsProvider->GetItem( i );
MARKER_BASE* marker = rcItem->GetParent();
if( ( aCurrent && rcItem == current_item )
|| ( aWarningsAndErrors && marker && !marker->IsExcluded() )
|| ( aExclusions && marker && marker->IsExcluded() ) )
{
wxDataViewItem markerItem = ToItem( m_tree[i] );
wxDataViewItemArray childItems;
@ -418,24 +430,14 @@ void RC_TREE_MODEL::DeleteCurrentItem( bool aDeep )
ItemDeleted( parentItem, markerItem );
m_rcItemsProvider->DeleteItem( i, aDeep );
if( !aWarningsAndErrors && !aExclusions )
break;
}
}
}
void RC_TREE_MODEL::DeleteAllItems()
{
if( m_rcItemsProvider )
{
m_rcItemsProvider->DeleteAllItems();
m_tree.clear();
Cleared();
}
}
void RC_TREE_MODEL::onSizeView( wxSizeEvent& aEvent )
{
int width = m_view->GetMainWindow()->GetRect().GetWidth() - WX_DATAVIEW_WINDOW_PADDING;

View File

@ -59,12 +59,6 @@ public:
*/
virtual void DeleteItem( int aIndex, bool aDeep ) = 0;
/**
* Function DeleteAllItems
* removes and deletes all the items in the list.
*/
virtual void DeleteAllItems() = 0;
virtual ~RC_ITEMS_PROVIDER() { }
};
@ -278,7 +272,7 @@ public:
void ValueChanged( RC_TREE_NODE* aNode );
void DeleteCurrentItem( bool aDeep );
void DeleteAllItems();
void DeleteItems( bool aCurrent, bool aWarningsAndErrors, bool aExclusions, bool aDeep );
private:
void rebuildModel( RC_ITEMS_PROVIDER* aProvider, int aSeverities );
@ -291,8 +285,6 @@ private:
RC_ITEMS_PROVIDER* m_rcItemsProvider; // I own this, but not its contents
std::vector<RC_TREE_NODE*> m_tree; // I own this
mutable const RC_ITEM* m_lastQueried; // Used as a massive hack to restore the
// widget's scroll position.
};

View File

@ -120,7 +120,27 @@ void DIALOG_ERC::updateDisplayedCounts()
*/
void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event )
{
deleteAllMarkers();
bool includeExclusions = false;
int numExcluded = 0;
if( m_markerProvider )
numExcluded += m_markerProvider->GetCount( RPT_SEVERITY_EXCLUSION );
if( numExcluded > 0 )
{
wxMessageDialog dlg( this, _( "Delete exclusions too?" ), _( "Delete All Markers" ),
wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
dlg.SetYesNoLabels( _( "Errors and Warnings Only" ) , _( "Errors, Warnings and Exclusions" ) );
int ret = dlg.ShowModal();
if( ret == wxID_CANCEL )
return;
else if( ret == wxID_NO )
includeExclusions = true;
}
deleteAllMarkers( includeExclusions );
updateDisplayedCounts();
m_parent->GetCanvas()->Refresh();
@ -159,7 +179,7 @@ void DIALOG_ERC::syncCheckboxes()
void DIALOG_ERC::OnRunERCClick( wxCommandEvent& event )
{
wxBusyCursor busy;
deleteAllMarkers();
deleteAllMarkers( true );
m_MessagesList->Clear();
wxSafeYield(); // m_MarkersList must be redraw
@ -557,12 +577,12 @@ void DIALOG_ERC::OnSeverity( wxCommandEvent& aEvent )
}
void DIALOG_ERC::deleteAllMarkers()
void DIALOG_ERC::deleteAllMarkers( bool aIncludeExclusions )
{
// Clear current selection list to avoid selection of deleted items
m_parent->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true );
m_markerTreeModel->DeleteAllItems();
m_markerTreeModel->DeleteItems( false, true, aIncludeExclusions, true );
}

View File

@ -67,7 +67,7 @@ private:
bool writeReport( const wxString& aFullFileName );
void deleteAllMarkers();
void deleteAllMarkers( bool aIncludeExclusions );
void syncCheckboxes();
void updateDisplayedCounts();

View File

@ -315,11 +315,3 @@ void SHEETLIST_ERC_ITEMS_PROVIDER::DeleteItem( int aIndex, bool aDeep )
screens.DeleteMarker( marker );
}
}
void SHEETLIST_ERC_ITEMS_PROVIDER::DeleteAllItems()
{
SCH_SCREENS screens( m_schematic->Root() );
screens.DeleteAllMarkers( MARKER_BASE::MARKER_ERC );
m_filteredMarkers.clear();
}

View File

@ -190,8 +190,6 @@ public:
ERC_ITEM* GetItem( int aIndex ) override;
void DeleteItem( int aIndex, bool aDeep ) override;
void DeleteAllItems() override;
};

View File

@ -1311,7 +1311,8 @@ void SCH_SCREENS::DeleteMarker( SCH_MARKER* aMarker )
}
void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, int aErrorCode )
void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, int aErrorCode,
bool aIncludeExclusions )
{
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
{
@ -1322,8 +1323,9 @@ void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, int a
SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
RC_ITEM* rcItem = marker->GetRCItem();
if( marker->GetMarkerType() == aMarkerType &&
( aErrorCode == ERCE_UNSPECIFIED || rcItem->GetErrorCode() == aErrorCode ) )
if( marker->GetMarkerType() == aMarkerType
&& ( aErrorCode == ERCE_UNSPECIFIED || rcItem->GetErrorCode() == aErrorCode )
&& ( !marker->IsExcluded() || aIncludeExclusions ) )
{
markers.push_back( item );
}
@ -1335,9 +1337,10 @@ void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, int a
}
void SCH_SCREENS::DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType )
void SCH_SCREENS::DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType,
bool aIncludeExclusions )
{
DeleteMarkers( aMarkerType, ERCE_UNSPECIFIED );
DeleteMarkers( aMarkerType, ERCE_UNSPECIFIED, aIncludeExclusions );
}

View File

@ -566,12 +566,13 @@ public:
* the list.
* @param aMarkerType Type of markers to be deleted.
*/
void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType );
void DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, bool aIncludeExclusions );
/**
* Delete all markers of a particular type and error code.
*/
void DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode );
void DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerTyp, int aErrorCode,
bool aIncludeExclusions = true );
/**
* Delete a specific marker.

View File

@ -106,17 +106,6 @@ public:
m_sourceVector->erase( m_sourceVector->begin() + aIndex );
}
}
void DeleteAllItems() override
{
if( m_sourceVector )
{
for( CLEANUP_ITEM* item : *m_sourceVector )
delete item;
m_sourceVector->clear();
}
}
};

View File

@ -188,7 +188,7 @@ void DIALOG_DRC::OnRunDRCClick( wxCommandEvent& aEvent )
m_tester->m_testFootprints = m_cbTestFootprints->GetValue();
m_brdEditor->RecordDRCExclusions();
deleteAllMarkers();
deleteAllMarkers( true );
wxBeginBusyCursor();
wxWindowDisabler disabler;
@ -508,13 +508,12 @@ void DIALOG_DRC::refreshBoardEditor()
}
void DIALOG_DRC::deleteAllMarkers()
void DIALOG_DRC::deleteAllMarkers( bool aIncludeExclusions )
{
// Clear current selection list to avoid selection of deleted items
m_brdEditor->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
m_markerTreeModel->DeleteAllItems();
m_unconnectedTreeModel->DeleteAllItems();
m_markerTreeModel->DeleteItems( false, true, aIncludeExclusions, true );
}
@ -594,7 +593,33 @@ void DIALOG_DRC::OnDeleteOneClick( wxCommandEvent& aEvent )
void DIALOG_DRC::OnDeleteAllClick( wxCommandEvent& aEvent )
{
deleteAllMarkers();
bool includeExclusions = false;
int numExcluded = 0;
if( m_markersProvider )
numExcluded += m_markersProvider->GetCount( RPT_SEVERITY_EXCLUSION );
if( m_unconnectedItemsProvider )
numExcluded += m_unconnectedItemsProvider->GetCount( RPT_SEVERITY_EXCLUSION );
if( m_footprintWarningsProvider )
numExcluded += m_footprintWarningsProvider->GetCount( RPT_SEVERITY_EXCLUSION );
if( numExcluded > 0 )
{
wxMessageDialog dlg( this, _( "Delete exclusions too?" ), _( "Delete All Markers" ),
wxYES_NO | wxCANCEL | wxCENTER | wxICON_QUESTION );
dlg.SetYesNoLabels( _( "Errors and Warnings Only" ) , _( "Errors, Warnings and Exclusions" ) );
int ret = dlg.ShowModal();
if( ret == wxID_CANCEL )
return;
else if( ret == wxID_NO )
includeExclusions = true;
}
deleteAllMarkers( includeExclusions );
refreshBoardEditor();
updateDisplayedCounts();

View File

@ -89,7 +89,7 @@ private:
void OnChangingNotebookPage( wxNotebookEvent& aEvent ) override;
void deleteAllMarkers();
void deleteAllMarkers( bool aIncludeExclusions );
void refreshBoardEditor();
BOARD_DESIGN_SETTINGS& bds() { return m_currentBoard->GetDesignSettings(); }

View File

@ -159,12 +159,6 @@ public:
if( aDeep )
m_board->Delete( marker );
}
void DeleteAllItems() override
{
m_board->DeleteMARKERs();
m_filteredMarkers.clear();
}
};
@ -252,19 +246,6 @@ public:
}
}
}
void DeleteAllItems() override
{
if( m_sourceVector )
{
for( DRC_ITEM* item : *m_sourceVector )
delete item;
m_sourceVector->clear();
}
m_filteredVector.clear(); // no ownership of DRC_ITEM pointers
}
};