diff --git a/common/rc_item.cpp b/common/rc_item.cpp index a9c484702a..9eaa781dc6 100644 --- a/common/rc_item.cpp +++ b/common/rc_item.cpp @@ -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 ); - break; + + 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; diff --git a/common/rc_item.h b/common/rc_item.h index dc3562b113..eab8cdefa0 100644 --- a/common/rc_item.h +++ b/common/rc_item.h @@ -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 m_tree; // I own this - mutable const RC_ITEM* m_lastQueried; // Used as a massive hack to restore the - // widget's scroll position. }; diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 1b4b2625c5..7924cf6ee3 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -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 ); } diff --git a/eeschema/dialogs/dialog_erc.h b/eeschema/dialogs/dialog_erc.h index cddb331936..a114e5e2e5 100644 --- a/eeschema/dialogs/dialog_erc.h +++ b/eeschema/dialogs/dialog_erc.h @@ -67,7 +67,7 @@ private: bool writeReport( const wxString& aFullFileName ); - void deleteAllMarkers(); + void deleteAllMarkers( bool aIncludeExclusions ); void syncCheckboxes(); void updateDisplayedCounts(); diff --git a/eeschema/erc_settings.cpp b/eeschema/erc_settings.cpp index 305957ed49..829a8fb3e1 100644 --- a/eeschema/erc_settings.cpp +++ b/eeschema/erc_settings.cpp @@ -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(); -} diff --git a/eeschema/erc_settings.h b/eeschema/erc_settings.h index 9a35f34c10..17243a2a85 100644 --- a/eeschema/erc_settings.h +++ b/eeschema/erc_settings.h @@ -190,8 +190,6 @@ public: ERC_ITEM* GetItem( int aIndex ) override; void DeleteItem( int aIndex, bool aDeep ) override; - - void DeleteAllItems() override; }; diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index bee11c2883..ff59f7f6c9 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -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( 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 ); } diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 3b13b833c5..275788b0e0 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -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. diff --git a/pcbnew/cleanup_item.h b/pcbnew/cleanup_item.h index 820a1bf8f6..e03655969f 100644 --- a/pcbnew/cleanup_item.h +++ b/pcbnew/cleanup_item.h @@ -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(); - } - } }; diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index c5a6198855..099c39eba6 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -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(); diff --git a/pcbnew/dialogs/dialog_drc.h b/pcbnew/dialogs/dialog_drc.h index b2c8312074..38706f449f 100644 --- a/pcbnew/dialogs/dialog_drc.h +++ b/pcbnew/dialogs/dialog_drc.h @@ -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(); } diff --git a/pcbnew/drc/drc_provider.h b/pcbnew/drc/drc_provider.h index 8a67886120..4b14cdddeb 100644 --- a/pcbnew/drc/drc_provider.h +++ b/pcbnew/drc/drc_provider.h @@ -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 - } };