diff --git a/eeschema/menubar.cpp b/eeschema/menubar.cpp index 5ab78f17e0..9808a2cb28 100644 --- a/eeschema/menubar.cpp +++ b/eeschema/menubar.cpp @@ -248,8 +248,11 @@ void SCH_EDIT_FRAME::ReCreateMenuBar() toolsMenu->AppendSeparator(); toolsMenu->Add( ACTIONS::showSymbolEditor ); toolsMenu->Add( EE_ACTIONS::updateSymbols ); + + toolsMenu->AppendSeparator(); toolsMenu->Add( EE_ACTIONS::rescueSymbols ); toolsMenu->Add( EE_ACTIONS::remapSymbols ); + toolsMenu->Add( EE_ACTIONS::repairSchematic ); toolsMenu->AppendSeparator(); toolsMenu->Add( EE_ACTIONS::editSymbolFields ); diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index 3f35792234..218e6b917e 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -650,6 +650,12 @@ TOOL_ACTION EE_ACTIONS::toggleForceHV( "eeschema.EditorControl.forceHVLines", _( "Force H/V Wires and Buses" ), _( "Switch H & V only mode for new wires and buses" ), BITMAPS::lines90 ); +TOOL_ACTION EE_ACTIONS::repairSchematic( "eeschema.EditorControl.repairSchematic", + AS_GLOBAL, 0, "", + _( "Repair Schematic" ), + _( "Run various diagnostics and attempt to repair schematic" ), + BITMAPS::rescue ); + // Python Console TOOL_ACTION EE_ACTIONS::showPythonConsole( "eeschema.EditorControl.showPythonConsole", AS_GLOBAL, 0, "", diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index 8a4c5c5953..d75067a2ab 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -208,6 +208,7 @@ public: static TOOL_ACTION exportSymbolView; static TOOL_ACTION exportSymbolAsSVG; static TOOL_ACTION showPythonConsole; + static TOOL_ACTION repairSchematic; // SPICE static TOOL_ACTION runSimulation; diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index e62f54f8ff..eeec0c79c3 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -2151,6 +2151,94 @@ int SCH_EDITOR_CONTROL::TogglePythonConsole( const TOOL_EVENT& aEvent ) } +int SCH_EDITOR_CONTROL::RepairSchematic( const TOOL_EVENT& aEvent ) +{ + int errors = 0; + wxString details; + bool quiet = aEvent.Parameter(); + + // Repair duplicate IDs. + std::map ids; + int duplicates = 0; + + auto processItem = + [&]( EDA_ITEM* aItem ) + { + auto it = ids.find( aItem->m_Uuid ); + + if( it != ids.end() && it->second != aItem ) + { + duplicates++; + const_cast( aItem->m_Uuid ) = KIID(); + } + + ids[ aItem->m_Uuid ] = aItem; + }; + + // Symbol IDs are the most important, so give them the first crack at "claiming" a + // particular KIID. + + for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() ) + { + SCH_SCREEN* screen = sheet.LastScreen(); + + for( SCH_ITEM* aItem : screen->Items().OfType( SCH_SYMBOL_T ) ) + { + processItem( aItem ); + + for( SCH_PIN* pin : static_cast( aItem )->GetPins( &sheet ) ) + processItem( pin ); + } + } + + for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() ) + { + SCH_SCREEN* screen = sheet.LastScreen(); + + for( SCH_ITEM* aItem : screen->Items() ) + { + processItem( aItem ); + + aItem->RunOnChildren( + [&]( SCH_ITEM* aChild ) + { + processItem( aItem ); + } ); + } + } + + /******************************* + * Your test here + */ + + /******************************* + * Inform the user + */ + + if( duplicates ) + { + errors += duplicates; + details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates ); + } + + if( errors ) + { + m_frame->OnModify(); + + wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors ); + + if( !quiet ) + DisplayInfoMessage( m_frame, msg, details ); + } + else if( !quiet ) + { + DisplayInfoMessage( m_frame, _( "No errors found." ) ); + } + + return 0; +} + + void SCH_EDITOR_CONTROL::setTransitions() { Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() ); @@ -2158,7 +2246,7 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() ); //Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveCopyAs.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs, EE_ACTIONS::saveCurrSheetCopyAs.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs, EE_ACTIONS::saveCurrSheetCopyAs.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ShowSchematicSetup, EE_ACTIONS::schematicSetup.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() ); @@ -2227,5 +2315,7 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::ToggleHiddenFields, EE_ACTIONS::toggleHiddenFields.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ToggleForceHV, EE_ACTIONS::toggleForceHV.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::TogglePythonConsole, EE_ACTIONS::showPythonConsole.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::TogglePythonConsole, EE_ACTIONS::showPythonConsole.MakeEvent() ); + + Go( &SCH_EDITOR_CONTROL::RepairSchematic, EE_ACTIONS::repairSchematic.MakeEvent() ); } diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index dc05e87e54..1314f9fc82 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -140,6 +140,8 @@ public: int ToggleForceHV( const TOOL_EVENT& aEvent ); int TogglePythonConsole( const TOOL_EVENT& aEvent ); + int RepairSchematic( const TOOL_EVENT& aEvent ); + void AssignFootprints( const std::string& aChangedSetOfReferences ); /**