diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index a1fac5af46..6f40cb7a29 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -548,6 +548,12 @@ TOOL_ACTION EE_ACTIONS::remapSymbols( "eeschema.EditorControl.remapSymbols", _( "Remap legacy library symbols to symbol library table" ), rescue_xpm ); +TOOL_ACTION EE_ACTIONS::refreshSymbolFromLibrary( "eeschema.EditorControl.refreshSymbolFromLibrary", + AS_GLOBAL, 0, "", + _( "Update from Symbol Library" ), + _( "Update from the symbol library using the library identifier" ), + refresh_xpm ); + TOOL_ACTION EE_ACTIONS::showBusManager( "eeschema.EditorControl.showBusManager", AS_GLOBAL, 0, "", _( "Bus Definitions..." ), _( "Manage bus definitions" ), diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index 786f83bfe8..2c841927b6 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -151,6 +151,7 @@ public: static TOOL_ACTION rescueSymbols; static TOOL_ACTION remapSymbols; + static TOOL_ACTION refreshSymbolFromLibrary; // Suite operations static TOOL_ACTION editWithLibEdit; diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index c96400d067..39248e5a6c 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -120,6 +120,8 @@ public: void BrightenItem( EDA_ITEM* aItem ); void UnbrightenItem( EDA_ITEM* aItem ); + void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); } + ///> Find (but don't select) node under cursor EDA_ITEM* GetNode( VECTOR2I aPosition ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 29afd9851b..466df2a8ac 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -27,10 +27,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -268,7 +270,7 @@ bool SCH_EDIT_TOOL::Init() auto wireSelectionCondition = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T ); auto busSelectionCondition = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T ); auto singleSheetCondition = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T ); - + auto symbolsOnlyCondition = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_COMPONENT_T ); // // Add edit actions to the move tool menu // @@ -347,6 +349,7 @@ bool SCH_EDIT_TOOL::Init() selToolMenu.AddItem( EE_ACTIONS::editFootprint, E_C::SingleSymbol, 200 ); selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition, 200 ); selToolMenu.AddItem( EE_ACTIONS::toggleDeMorgan, E_C::SingleSymbol, 200 ); + selToolMenu.AddItem( EE_ACTIONS::refreshSymbolFromLibrary, symbolsOnlyCondition, 200 ); std::shared_ptr symUnitMenu3 = std::make_shared(); symUnitMenu3->SetTool( m_selectionTool ); @@ -1256,6 +1259,80 @@ int SCH_EDIT_TOOL::ConvertDeMorgan( const TOOL_EVENT& aEvent ) } +int SCH_EDIT_TOOL::RefreshSymbolFromLibrary( const TOOL_EVENT& aEvent ) +{ + wxString msg; + bool appendToUndo = false; + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); + + if( selection.Empty() ) + return 0; + + WX_INFOBAR* infoBar = m_frame->GetInfoBar(); + + wxCHECK( infoBar, 0 ); + + INFOBAR_REPORTER reporter( infoBar ); + + SCH_SCREEN* currentScreen = m_frame->GetScreen(); + + wxCHECK( currentScreen, 0 ); + + for( auto item : selection ) + { + SCH_COMPONENT* symbol = dynamic_cast( item ); + + wxCHECK( symbol, 0 ); + + // This needs to be done before the LIB_ID is changed to prevent stale library symbols in + // the schematic file. + currentScreen->Remove( symbol ); + + if( !symbol->IsNew() ) + { + m_frame->SaveCopyInUndoList( symbol, UR_CHANGED, appendToUndo ); + appendToUndo = true; + } + + LIB_ID id = symbol->GetLibId(); + + if( !id.IsValid() ) + { + msg.Printf( _( "'%s' is not a valid library indentifier." ), + id.GetUniStringLibId() ); + reporter.Report( msg, RPT_SEVERITY_WARNING ); + continue; + } + + LIB_PART* libSymbol = m_frame->Prj().SchSymbolLibTable()->LoadSymbol( id ); + + if( !libSymbol ) + { + msg.Printf( _( "Symbol '%s' not found in symbol library '%s'." ), + id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() ); + reporter.Report( msg, RPT_SEVERITY_WARNING ); + continue; + } + + symbol->SetLibSymbol( libSymbol->Flatten().release() ); + currentScreen->Append( symbol ); + m_selectionTool->SelectHighlightItem( symbol ); + updateView( symbol ); + } + + if( selection.IsHover() ) + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); + + if( reporter.HasMessage() ) + reporter.Finalize(); + + m_frame->GetCanvas()->Refresh(); + m_frame->OnModify(); + + return 0; +} + + int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems ); @@ -1643,7 +1720,8 @@ void SCH_EDIT_TOOL::setTransitions() Go( &SCH_EDIT_TOOL::ConvertDeMorgan, EE_ACTIONS::toggleDeMorgan.MakeEvent() ); Go( &SCH_EDIT_TOOL::ConvertDeMorgan, EE_ACTIONS::showDeMorganStandard.MakeEvent() ); Go( &SCH_EDIT_TOOL::ConvertDeMorgan, EE_ACTIONS::showDeMorganAlternate.MakeEvent() ); - + Go( &SCH_EDIT_TOOL::RefreshSymbolFromLibrary, + EE_ACTIONS::refreshSymbolFromLibrary.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toHLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toGLabel.MakeEvent() ); diff --git a/eeschema/tools/sch_edit_tool.h b/eeschema/tools/sch_edit_tool.h index c0e29fe71f..2d2048031d 100644 --- a/eeschema/tools/sch_edit_tool.h +++ b/eeschema/tools/sch_edit_tool.h @@ -54,6 +54,8 @@ public: int UpdateFields( const TOOL_EVENT& aEvent ); int ConvertDeMorgan( const TOOL_EVENT& aEvent ); + int RefreshSymbolFromLibrary( const TOOL_EVENT& aEvent ); + /** * Change a text type to another one. *