Add footprint repair tool (currently just for duplicate IDs).

This commit is contained in:
Jeff Young 2021-05-21 17:52:11 +01:00
parent 0d8a9a1091
commit baf868fce7
6 changed files with 99 additions and 4 deletions

View File

@ -1019,6 +1019,9 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
mgr->SetConditions( PCB_ACTIONS::checkFootprint, ENABLE( cond.HasItems() ) );
mgr->SetConditions( PCB_ACTIONS::repairFootprint, ENABLE( cond.HasItems() ) );
auto highContrastCond =
[this] ( const SELECTION& )

View File

@ -218,6 +218,9 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar()
ID_ADD_FOOTPRINT_TO_BOARD,
BITMAPS::insert_module_board );
toolsMenu->AppendSeparator();
toolsMenu->Add( PCB_ACTIONS::repairFootprint );
//-- Preferences menu -------------------------------------------------
//

View File

@ -510,6 +510,85 @@ void FOOTPRINT_EDITOR_CONTROL::DestroyCheckerDialog()
}
int FOOTPRINT_EDITOR_CONTROL::RepairFootprint( const TOOL_EVENT& aEvent )
{
FOOTPRINT* footprint = board()->Footprints().front();
int errors = 0;
wxString details;
/*******************************
* Repair duplicate IDs and missing nets
*/
std::set<KIID> ids;
int duplicates = 0;
auto processItem =
[&]( EDA_ITEM* aItem )
{
if( ids.count( aItem->m_Uuid ) )
{
duplicates++;
const_cast<KIID&>( aItem->m_Uuid ) = KIID();
}
ids.insert( aItem->m_Uuid );
};
// Footprint IDs are the most important, so give them the first crack at "claiming" a
// particular KIID.
processItem( footprint );
// After that the principal use is for DRC marker pointers, which are most likely to pads.
for( PAD* pad : footprint->Pads() )
processItem( pad );
// From here out I don't think order matters much.
processItem( &footprint->Reference() );
processItem( &footprint->Value() );
for( BOARD_ITEM* item : footprint->GraphicalItems() )
processItem( item );
for( ZONE* zone : footprint->Zones() )
processItem( zone );
for( PCB_GROUP* group : footprint->Groups() )
processItem( group );
if( duplicates )
{
errors += duplicates;
details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
}
/*******************************
* Your test here
*/
/*******************************
* Inform the user
*/
if( errors )
{
m_frame->OnModify();
wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
DisplayInfoMessage( m_frame, msg, details );
}
else
{
DisplayInfoMessage( m_frame, _( "No footprint problems found." ) );
}
return 0;
}
void FOOTPRINT_EDITOR_CONTROL::setTransitions()
{
Go( &FOOTPRINT_EDITOR_CONTROL::NewFootprint, PCB_ACTIONS::newFootprint.MakeEvent() );
@ -531,6 +610,7 @@ void FOOTPRINT_EDITOR_CONTROL::setTransitions()
Go( &FOOTPRINT_EDITOR_CONTROL::CleanupGraphics, PCB_ACTIONS::cleanupGraphics.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::CheckFootprint, PCB_ACTIONS::checkFootprint.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::RepairFootprint, PCB_ACTIONS::repairFootprint.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::PinLibrary, ACTIONS::pinLibrary.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::UnpinLibrary, ACTIONS::unpinLibrary.MakeEvent() );

View File

@ -72,6 +72,8 @@ public:
int CheckFootprint( const TOOL_EVENT& aEvent );
void DestroyCheckerDialog();
int RepairFootprint( const TOOL_EVENT& aEvent );
/**
* Edit the properties used for new pad creation.
*/

View File

@ -1072,6 +1072,12 @@ TOOL_ACTION PCB_ACTIONS::repairBoard( "pcbnew.Control.repairBoard",
_( "Run various diagnostics and attempt to repair board" ),
BITMAPS::rescue );
TOOL_ACTION PCB_ACTIONS::repairFootprint( "pcbnew.ModuleEditor.repairFootprint",
AS_GLOBAL, 0, "",
_( "Repair Footprint" ),
_( "Run various diagnostics and attempt to repair footprint" ),
BITMAPS::rescue );
// PLACEMENT_TOOL
//

View File

@ -441,6 +441,7 @@ public:
static TOOL_ACTION boardStatistics;
static TOOL_ACTION boardReannotate;
static TOOL_ACTION repairBoard;
static TOOL_ACTION repairFootprint;
static TOOL_ACTION inspectClearance;
static TOOL_ACTION inspectConstraints;