ADDED board repair tool.

Currently it just fixes duplicate UUIDs.
This commit is contained in:
Jeff Young 2020-08-11 15:01:26 +01:00
parent 5ab39b7c06
commit a0f95855d1
5 changed files with 106 additions and 0 deletions

View File

@ -486,6 +486,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
toolsMenu->AddSeparator(); toolsMenu->AddSeparator();
toolsMenu->AddItem( PCB_ACTIONS::removeUnusedPads, SELECTION_CONDITIONS::ShowAlways ); toolsMenu->AddItem( PCB_ACTIONS::removeUnusedPads, SELECTION_CONDITIONS::ShowAlways );
toolsMenu->AddItem( PCB_ACTIONS::repairBoard, SELECTION_CONDITIONS::ShowAlways );
#if defined(KICAD_SCRIPTING_WXPYTHON) #if defined(KICAD_SCRIPTING_WXPYTHON)
auto pythonConsoleShownCondition = [] ( const SELECTION& aSel ) { auto pythonConsoleShownCondition = [] ( const SELECTION& aSel ) {

View File

@ -972,6 +972,13 @@ TOOL_ACTION PCB_ACTIONS::boardReannotate( "pcbnew.ReannotateTool.ShowReannotateD
_( "Geographical Reannotate..." ), _( "Reannotate PCB in geographical order" ), _( "Geographical Reannotate..." ), _( "Reannotate PCB in geographical order" ),
annotate_xpm ); annotate_xpm );
TOOL_ACTION PCB_ACTIONS::repairBoard( "pcbnew.Control.repairBoard",
AS_GLOBAL, 0, "",
_( "Repair Board" ),
_( "Run various diagnostics and attempt to repair board" ),
rescue_xpm );
// PLACEMENT_TOOL // PLACEMENT_TOOL
// //
TOOL_ACTION PCB_ACTIONS::alignTop( "pcbnew.AlignAndDistribute.alignTop", TOOL_ACTION PCB_ACTIONS::alignTop( "pcbnew.AlignAndDistribute.alignTop",

View File

@ -408,6 +408,7 @@ public:
static TOOL_ACTION showEeschema; static TOOL_ACTION showEeschema;
static TOOL_ACTION boardStatistics; static TOOL_ACTION boardStatistics;
static TOOL_ACTION boardReannotate; static TOOL_ACTION boardReannotate;
static TOOL_ACTION repairBoard;
// Appearance controls // Appearance controls
static TOOL_ACTION clearHighlight; static TOOL_ACTION clearHighlight;

View File

@ -35,6 +35,7 @@
#include <class_pcb_target.h> #include <class_pcb_target.h>
#include <class_track.h> #include <class_track.h>
#include <class_zone.h> #include <class_zone.h>
#include <class_marker_pcb.h>
#include <collectors.h> #include <collectors.h>
#include <confirm.h> #include <confirm.h>
#include <cstdint> #include <cstdint>
@ -393,6 +394,100 @@ int PCB_EDITOR_CONTROL::GenerateFabFiles( const TOOL_EVENT& aEvent )
} }
int PCB_EDITOR_CONTROL::RepairBoard( const TOOL_EVENT& aEvent )
{
int errors = 0;
wxString details;
/*******************************
* Repair duplicate IDs
*/
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 );
};
// Module IDs are the most important, so give them the first crack at "owning" a particular
// KIID.
for( MODULE* module : board()->Modules() )
processItem( module );
// After that the principal use is for DRC marker pointers, which are most likely to pads
// or tracks.
for( MODULE* module : board()->Modules() )
{
for( D_PAD* pad : module->Pads() )
processItem( pad );
}
for( TRACK* track : board()->Tracks() )
processItem( track );
// From here out I don't think order matters much.
for( MODULE* module : board()->Modules() )
{
processItem( &module->Reference() );
processItem( &module->Value() );
for( BOARD_ITEM* item : module->GraphicalItems() )
processItem( item );
for( ZONE_CONTAINER* zone : module->Zones() )
processItem( zone );
}
for( BOARD_ITEM* drawing : board()->Drawings() )
processItem( drawing );
for( ZONE_CONTAINER* zone : board()->GetZoneList() )
processItem( zone );
for( MARKER_PCB* marker : board()->Markers() )
processItem( marker );
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 board problems found." ) );
}
return 0;
}
int PCB_EDITOR_CONTROL::UpdatePCBFromSchematic( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::UpdatePCBFromSchematic( const TOOL_EVENT& aEvent )
{ {
NETLIST netlist; NETLIST netlist;
@ -1249,6 +1344,7 @@ void PCB_EDITOR_CONTROL::setTransitions()
Go( &PCB_EDITOR_CONTROL::ToggleMicrowaveToolbar, PCB_ACTIONS::showMicrowaveToolbar.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::ToggleMicrowaveToolbar, PCB_ACTIONS::showMicrowaveToolbar.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::TogglePythonConsole, PCB_ACTIONS::showPythonConsole.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::TogglePythonConsole, PCB_ACTIONS::showPythonConsole.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::FlipPcbView, PCB_ACTIONS::flipBoard.MakeEvent() ); Go( &PCB_EDITOR_CONTROL::FlipPcbView, PCB_ACTIONS::flipBoard.MakeEvent() );
Go( &PCB_EDITOR_CONTROL::RepairBoard, PCB_ACTIONS::repairBoard.MakeEvent() );
} }

View File

@ -66,6 +66,7 @@ public:
int GenerateDrillFiles( const TOOL_EVENT& aEvent ); int GenerateDrillFiles( const TOOL_EVENT& aEvent );
int GeneratePosFile( const TOOL_EVENT& aEvent ); int GeneratePosFile( const TOOL_EVENT& aEvent );
int GenerateFabFiles( const TOOL_EVENT& aEvent ); int GenerateFabFiles( const TOOL_EVENT& aEvent );
int RepairBoard( const TOOL_EVENT& aEvent );
int UpdatePCBFromSchematic( const TOOL_EVENT& aEvent ); int UpdatePCBFromSchematic( const TOOL_EVENT& aEvent );
int UpdateSchematicFromPCB( const TOOL_EVENT& aEvent ); int UpdateSchematicFromPCB( const TOOL_EVENT& aEvent );