From 521aa5b5ae926301136df85775eb135fcd77c9db Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 15 Apr 2023 10:54:53 +0100 Subject: [PATCH] Update DRC exclusions model to match terminology. DRC exclusions were originally written following the C++ pragma model (ie: allow this violation here). However, the "exclusion" terminology we used in the GUI suggests a model model where the exclusions go away when the violation no longer exists. Fixes https://gitlab.com/kicad/code/kicad/issues/14351 --- pcbnew/board.cpp | 39 ++++++++++--------- pcbnew/board.h | 6 ++- pcbnew/files.cpp | 2 +- pcbnew/pcb_edit_frame.cpp | 4 +- pcbnew/pcb_edit_frame.h | 5 ++- .../scripting/pcbnew_scripting_helpers.cpp | 2 +- pcbnew/tools/drc_tool.cpp | 2 +- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index f28d21bdd7..0448916c45 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -306,7 +306,7 @@ void BOARD::UpdateRatsnestExclusions() } -std::vector BOARD::ResolveDRCExclusions() +std::vector BOARD::ResolveDRCExclusions( bool aCreateMarkers ) { for( PCB_MARKER* marker : GetBoard()->Markers() ) { @@ -321,28 +321,31 @@ std::vector BOARD::ResolveDRCExclusions() std::vector newMarkers; - for( const wxString& exclusionData : m_designSettings->m_DrcExclusions ) + if( aCreateMarkers ) { - PCB_MARKER* marker = PCB_MARKER::Deserialize( exclusionData ); - - if( !marker ) - continue; - - // Check to see if items still exist - for( const KIID& guid : marker->GetRCItem()->GetIDs() ) + for( const wxString& exclusionData : m_designSettings->m_DrcExclusions ) { - if( GetItem( guid ) == DELETED_BOARD_ITEM::GetInstance() ) + PCB_MARKER* marker = PCB_MARKER::Deserialize( exclusionData ); + + if( !marker ) + continue; + + // Check to see if items still exist + for( const KIID& guid : marker->GetRCItem()->GetIDs() ) { - delete marker; - marker = nullptr; - break; + if( GetItem( guid ) == DELETED_BOARD_ITEM::GetInstance() ) + { + delete marker; + marker = nullptr; + break; + } } - } - if( marker ) - { - marker->SetExcluded( true ); - newMarkers.push_back( marker ); + if( marker ) + { + marker->SetExcluded( true ); + newMarkers.push_back( marker ); + } } } diff --git a/pcbnew/board.h b/pcbnew/board.h index d727d5489d..d365febfe6 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -460,8 +460,12 @@ public: /** * Rebuild DRC markers from the serialized data in BOARD_DESIGN_SETTINGS. + * + * @param aCreateMarkers if true, create markers from serialized data; if false only + * use serialized data to set existing markers to excluded. + * The former is used on board load; the later after a DRC. */ - std::vector ResolveDRCExclusions(); + std::vector ResolveDRCExclusions( bool aCreateMarkers ); /** * Update the visibility flags on the current unconnected ratsnest lines. diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 1c549408f2..c47968e625 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -826,7 +826,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // we should not ask PLUGINs to do these items: loadedBoard->BuildListOfNets(); - ResolveDRCExclusions(); + ResolveDRCExclusions( true ); m_toolManager->RunAction( PCB_ACTIONS::repairBoard, true, true); if( loadedBoard->IsModified() ) diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 410f52f6c6..bd2ceb8f61 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -984,11 +984,11 @@ void PCB_EDIT_FRAME::RecordDRCExclusions() } -void PCB_EDIT_FRAME::ResolveDRCExclusions() +void PCB_EDIT_FRAME::ResolveDRCExclusions( bool aCreateMarkers ) { BOARD_COMMIT commit( this ); - for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions() ) + for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions( aCreateMarkers ) ) { if( marker->GetMarkerType() == MARKER_BASE::MARKER_DRAWING_SHEET ) marker->GetRCItem()->SetItems( GetCanvas()->GetDrawingSheet() ); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 11623a75c1..ea98b473a6 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -238,9 +238,10 @@ public: void RecordDRCExclusions(); /** - * Update markers to match recorded exclusions. + * If aCreateMarkers then create DRC exclusion markers from the serialized data. If false, + * then use the serialized data to set exclusion flags on existing markers. */ - void ResolveDRCExclusions(); + void ResolveDRCExclusions( bool aCreateMarkers ); void Process_Special_Functions( wxCommandEvent& event ); void Tracks_and_Vias_Size_Event( wxCommandEvent& event ); diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index 8ea55b6d01..3ac97ceccd 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -183,7 +183,7 @@ BOARD* LoadBoard( wxString& aFileName, IO_MGR::PCB_FILE_T aFormat ) // Best efforts... } - for( PCB_MARKER* marker : brd->ResolveDRCExclusions() ) + for( PCB_MARKER* marker : brd->ResolveDRCExclusions( true ) ) brd->Add( marker ); brd->BuildConnectivity(); diff --git a/pcbnew/tools/drc_tool.cpp b/pcbnew/tools/drc_tool.cpp index c90b564d40..d927bab029 100644 --- a/pcbnew/tools/drc_tool.cpp +++ b/pcbnew/tools/drc_tool.cpp @@ -206,7 +206,7 @@ void DRC_TOOL::updatePointers() // update my pointers, m_editFrame is the only unchangeable one m_pcb = m_editFrame->GetBoard(); - m_editFrame->ResolveDRCExclusions(); + m_editFrame->ResolveDRCExclusions( false ); if( m_drcDialog ) m_drcDialog->UpdateData();