Make DRC exclusions work in cli & python DRC

The way exclusions work is actually silly, and you can end up with your project file losing them too.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11562
This commit is contained in:
Marek Roszko 2024-01-10 19:55:18 -05:00
parent 4b1fc9c129
commit d0236ca751
8 changed files with 32 additions and 20 deletions

View File

@ -2720,3 +2720,15 @@ bool BOARD::operator==( const BOARD_ITEM& aItem ) const
return true;
}
void BOARD::RecordDRCExclusions()
{
m_designSettings->m_DrcExclusions.clear();
for( PCB_MARKER* marker : m_markers )
{
if( marker->IsExcluded() )
m_designSettings->m_DrcExclusions.insert( marker->Serialize() );
}
}

View File

@ -477,6 +477,11 @@ public:
*/
std::vector<PCB_MARKER*> ResolveDRCExclusions( bool aCreateMarkers );
/**
* Scan existing markers and record data from any that are Excluded.
*/
void RecordDRCExclusions();
/**
* Update the visibility flags on the current unconnected ratsnest lines.
*/

View File

@ -285,7 +285,7 @@ void DIALOG_DRC::OnRunDRCClick( wxCommandEvent& aEvent )
m_footprintTestsRun = false;
m_cancelled = false;
m_frame->RecordDRCExclusions();
m_frame->GetBoard()->RecordDRCExclusions();
deleteAllMarkers( true );
std::vector<std::reference_wrapper<RC_ITEM>> violations = DRC_ITEM::GetItemsWithSeverities();

View File

@ -994,19 +994,6 @@ void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
}
void PCB_EDIT_FRAME::RecordDRCExclusions()
{
BOARD_DESIGN_SETTINGS& bds = GetBoard()->GetDesignSettings();
bds.m_DrcExclusions.clear();
for( PCB_MARKER* marker : GetBoard()->Markers() )
{
if( marker->IsExcluded() )
bds.m_DrcExclusions.insert( marker->Serialize() );
}
}
void PCB_EDIT_FRAME::ResolveDRCExclusions( bool aCreateMarkers )
{
BOARD_COMMIT commit( this );

View File

@ -233,11 +233,6 @@ public:
*/
void SetLastPath( LAST_PATH_TYPE aType, const wxString& aLastPath );
/**
* Scan existing markers and record data from any that are Excluded.
*/
void RecordDRCExclusions();
/**
* 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.

View File

@ -149,7 +149,7 @@ void PCB_EDIT_FRAME::SaveProjectLocalSettings()
project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
project.m_Viewports = m_appearancePanel->GetUserViewports();
RecordDRCExclusions();
GetBoard()->RecordDRCExclusions();
// Save render settings that aren't stored in PCB_DISPLAY_OPTIONS

View File

@ -1004,10 +1004,17 @@ int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob )
commit.Add( marker );
} );
brd->RecordDRCExclusions();
brd->DeleteMARKERs( true, true );
drcEngine->RunTests( units, drcJob->m_reportAllTrackErrors, false );
drcEngine->ClearViolationHandler();
commit.Push( _( "DRC" ), SKIP_UNDO | SKIP_SET_DIRTY );
// now "resolve" the drc exclusions again because its the only way to set exclusion status on a marker
for( PCB_MARKER* marker : brd->ResolveDRCExclusions( false ) )
brd->Add( marker );
std::shared_ptr<DRC_ITEMS_PROVIDER> markersProvider = std::make_shared<DRC_ITEMS_PROVIDER>(
brd, MARKER_BASE::MARKER_DRC, MARKER_BASE::MARKER_DRAWING_SHEET );

View File

@ -585,9 +585,15 @@ bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits,
}
} );
aBoard->RecordDRCExclusions();
aBoard->DeleteMARKERs( true, true );
engine->RunTests( aUnits, aReportAllTrackErrors, false );
engine->ClearViolationHandler();
// now "resolve" the drc exclusions again because its the only way to set exclusion status on a marker
for( PCB_MARKER* marker : aBoard->ResolveDRCExclusions( false ) )
aBoard->Add( marker );
// TODO: Unify this with DIALOG_DRC::writeReport
FILE* fp = wxFopen( aFileName, wxT( "w" ) );