Eeschema: add update symbol from library command to context menu.

Rather than displaying dialog that has every update option possible like
updating footprints in the board editor, this change updates the library
symbol immediately using the symbol library identifier and requires no
additional input from the user.

ADDED: Context menu entry for schematic symbols to update the symbol from
the symbol library using the existing library identifier.
This commit is contained in:
Wayne Stambaugh 2020-07-08 10:15:24 -04:00
parent 841b08f9a6
commit 4c383c51fa
5 changed files with 91 additions and 2 deletions

View File

@ -548,6 +548,12 @@ TOOL_ACTION EE_ACTIONS::remapSymbols( "eeschema.EditorControl.remapSymbols",
_( "Remap legacy library symbols to symbol library table" ), _( "Remap legacy library symbols to symbol library table" ),
rescue_xpm ); 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", TOOL_ACTION EE_ACTIONS::showBusManager( "eeschema.EditorControl.showBusManager",
AS_GLOBAL, 0, "", AS_GLOBAL, 0, "",
_( "Bus Definitions..." ), _( "Manage bus definitions" ), _( "Bus Definitions..." ), _( "Manage bus definitions" ),

View File

@ -151,6 +151,7 @@ public:
static TOOL_ACTION rescueSymbols; static TOOL_ACTION rescueSymbols;
static TOOL_ACTION remapSymbols; static TOOL_ACTION remapSymbols;
static TOOL_ACTION refreshSymbolFromLibrary;
// Suite operations // Suite operations
static TOOL_ACTION editWithLibEdit; static TOOL_ACTION editWithLibEdit;

View File

@ -120,6 +120,8 @@ public:
void BrightenItem( EDA_ITEM* aItem ); void BrightenItem( EDA_ITEM* aItem );
void UnbrightenItem( EDA_ITEM* aItem ); void UnbrightenItem( EDA_ITEM* aItem );
void SelectHighlightItem( EDA_ITEM* aItem ) { highlight( aItem, SELECTED ); }
///> Find (but don't select) node under cursor ///> Find (but don't select) node under cursor
EDA_ITEM* GetNode( VECTOR2I aPosition ); EDA_ITEM* GetNode( VECTOR2I aPosition );

View File

@ -27,10 +27,12 @@
#include <tools/ee_selection_tool.h> #include <tools/ee_selection_tool.h>
#include <tools/sch_line_wire_bus_tool.h> #include <tools/sch_line_wire_bus_tool.h>
#include <tools/sch_move_tool.h> #include <tools/sch_move_tool.h>
#include <widgets/infobar.h>
#include <ee_actions.h> #include <ee_actions.h>
#include <bitmaps.h> #include <bitmaps.h>
#include <confirm.h> #include <confirm.h>
#include <base_struct.h> #include <base_struct.h>
#include <reporter.h>
#include <sch_item.h> #include <sch_item.h>
#include <sch_component.h> #include <sch_component.h>
#include <sch_sheet.h> #include <sch_sheet.h>
@ -268,7 +270,7 @@ bool SCH_EDIT_TOOL::Init()
auto wireSelectionCondition = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T ); 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 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 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 // 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::editFootprint, E_C::SingleSymbol, 200 );
selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition, 200 ); selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition, 200 );
selToolMenu.AddItem( EE_ACTIONS::toggleDeMorgan, E_C::SingleSymbol, 200 ); selToolMenu.AddItem( EE_ACTIONS::toggleDeMorgan, E_C::SingleSymbol, 200 );
selToolMenu.AddItem( EE_ACTIONS::refreshSymbolFromLibrary, symbolsOnlyCondition, 200 );
std::shared_ptr<SYMBOL_UNIT_MENU> symUnitMenu3 = std::make_shared<SYMBOL_UNIT_MENU>(); std::shared_ptr<SYMBOL_UNIT_MENU> symUnitMenu3 = std::make_shared<SYMBOL_UNIT_MENU>();
symUnitMenu3->SetTool( m_selectionTool ); 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<SCH_COMPONENT*>( 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 ) int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
{ {
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems ); 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::toggleDeMorgan.MakeEvent() );
Go( &SCH_EDIT_TOOL::ConvertDeMorgan, EE_ACTIONS::showDeMorganStandard.MakeEvent() ); Go( &SCH_EDIT_TOOL::ConvertDeMorgan, EE_ACTIONS::showDeMorganStandard.MakeEvent() );
Go( &SCH_EDIT_TOOL::ConvertDeMorgan, EE_ACTIONS::showDeMorganAlternate.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::toLabel.MakeEvent() );
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toHLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toHLabel.MakeEvent() );
Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toGLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toGLabel.MakeEvent() );

View File

@ -54,6 +54,8 @@ public:
int UpdateFields( const TOOL_EVENT& aEvent ); int UpdateFields( const TOOL_EVENT& aEvent );
int ConvertDeMorgan( const TOOL_EVENT& aEvent ); int ConvertDeMorgan( const TOOL_EVENT& aEvent );
int RefreshSymbolFromLibrary( const TOOL_EVENT& aEvent );
/** /**
* Change a text type to another one. * Change a text type to another one.
* *