Fix broken symbol link in schematic after editing.

The save current symbol command had a different code path then save current
library so the schematic symbol was not being refresh after is was modified
in symbol editor.

Split out the save current symbol command from Process_Special_Functions()
to help reduce function growth hormone imbalance syndrome.

Some coding policy fixes and wxT() macro removal.

Fixes lp:1671456

https://bugs.launchpad.net/kicad/+bug/1671456
This commit is contained in:
Wayne Stambaugh 2017-03-10 08:38:39 -05:00
parent 7bf4c90be5
commit cc64c6af1d
5 changed files with 92 additions and 68 deletions

View File

@ -1,8 +1,8 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -181,10 +181,10 @@ enum id_eeschema_frm
ID_LIBEDIT_DIMENSIONS, ID_LIBEDIT_DIMENSIONS,
/* Library editor horizontal toolbar IDs. */ /* Library editor horizontal toolbar IDs. */
ID_LIBEDIT_SAVE_CURRENT_PART,
ID_LIBEDIT_SELECT_PART, ID_LIBEDIT_SELECT_PART,
ID_LIBEDIT_SELECT_CURRENT_LIB, ID_LIBEDIT_SELECT_CURRENT_LIB,
ID_LIBEDIT_SAVE_CURRENT_LIB, ID_LIBEDIT_SAVE_CURRENT_LIB,
ID_LIBEDIT_SAVE_CURRENT_PART,
ID_LIBEDIT_NEW_PART, ID_LIBEDIT_NEW_PART,
ID_LIBEDIT_NEW_PART_FROM_EXISTING, ID_LIBEDIT_NEW_PART_FROM_EXISTING,
ID_LIBEDIT_GET_FRAME_EDIT_PART, ID_LIBEDIT_GET_FRAME_EDIT_PART,

View File

@ -261,6 +261,7 @@ void LIB_EDIT_FRAME::RedrawComponent( wxDC* aDC, wxPoint aOffset )
} }
} }
void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{ {
if( GetScreen() == NULL ) if( GetScreen() == NULL )
@ -399,7 +400,8 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) ) if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{ {
libFileName.MakeAbsolute(); libFileName.MakeAbsolute();
msg = _( "Failed to rename old component library file " ) + backupFileName.GetFullPath(); msg = _( "Failed to rename old component library file " ) +
backupFileName.GetFullPath();
DisplayError( this, msg ); DisplayError( this, msg );
} }
} }
@ -445,21 +447,7 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
AppendMsgPanel( msg, msg1, BLUE ); AppendMsgPanel( msg, msg1, BLUE );
UpdateAliasSelectList(); UpdateAliasSelectList();
UpdatePartSelectList(); UpdatePartSelectList();
refreshSchematic();
// This is not the most effecient way to do this because the changed library may not have
// any effect on the schematic symbol links. Since this is not called very often, take the
// hit here rather than the myriad other places (including SCH_SCREEN::Draw()) where it was
// being called.
if( !newFile )
{
SCH_SCREENS schematic;
schematic.UpdateSymbolLinks();
// There may be no parent window so use KIWAY message to refresh the schematic editor
// in case any symbols have changed.
Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
}
return true; return true;
} }
@ -613,7 +601,6 @@ void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event )
} }
void LIB_EDIT_FRAME::CreateNewLibraryPart( wxCommandEvent& event ) void LIB_EDIT_FRAME::CreateNewLibraryPart( wxCommandEvent& event )
{ {
wxString name; wxString name;

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -96,7 +96,6 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting ) EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting )
EVT_TOOL( ID_LIBEDIT_SELECT_PART, LIB_EDIT_FRAME::LoadOneLibraryPart ) EVT_TOOL( ID_LIBEDIT_SELECT_PART, LIB_EDIT_FRAME::LoadOneLibraryPart )
EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_PART, LIB_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( wxID_UNDO, LIB_EDIT_FRAME::GetComponentFromUndoList ) EVT_TOOL( wxID_UNDO, LIB_EDIT_FRAME::GetComponentFromUndoList )
EVT_TOOL( wxID_REDO, LIB_EDIT_FRAME::GetComponentFromRedoList ) EVT_TOOL( wxID_REDO, LIB_EDIT_FRAME::GetComponentFromRedoList )
EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnEditComponentProperties ) EVT_TOOL( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnEditComponentProperties )
@ -110,6 +109,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_TOOL( ExportPartId, LIB_EDIT_FRAME::OnExportPart ) EVT_TOOL( ExportPartId, LIB_EDIT_FRAME::OnExportPart )
EVT_TOOL( CreateNewLibAndSavePartId, LIB_EDIT_FRAME::OnExportPart ) EVT_TOOL( CreateNewLibAndSavePartId, LIB_EDIT_FRAME::OnExportPart )
EVT_TOOL( ImportPartId, LIB_EDIT_FRAME::OnImportPart ) EVT_TOOL( ImportPartId, LIB_EDIT_FRAME::OnImportPart )
EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_PART, LIB_EDIT_FRAME::OnSaveCurrentPart )
EVT_COMBOBOX( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnSelectPart ) EVT_COMBOBOX( ID_LIBEDIT_SELECT_PART_NUMBER, LIB_EDIT_FRAME::OnSelectPart )
EVT_COMBOBOX( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnSelectAlias ) EVT_COMBOBOX( ID_LIBEDIT_SELECT_ALIAS, LIB_EDIT_FRAME::OnSelectAlias )
@ -274,19 +274,19 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
mesg.MessageToolbarPane(); mesg.MessageToolbarPane();
m_auimgr.AddPane( m_mainToolBar, m_auimgr.AddPane( m_mainToolBar,
wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) ); wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top().Row( 0 ) );
m_auimgr.AddPane( m_drawToolBar, m_auimgr.AddPane( m_drawToolBar,
wxAuiPaneInfo( vert ).Name( wxT( "m_VToolBar" ) ).Right() ); wxAuiPaneInfo( vert ).Name( "m_VToolBar" ).Right() );
m_auimgr.AddPane( m_optionsToolBar, m_auimgr.AddPane( m_optionsToolBar,
wxAuiPaneInfo( vert ).Name( wxT( "m_optionsToolBar" ) ).Left() ); wxAuiPaneInfo( vert ).Name( "m_optionsToolBar" ).Left() );
m_auimgr.AddPane( m_canvas, m_auimgr.AddPane( m_canvas,
wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
m_auimgr.AddPane( m_messagePanel, m_auimgr.AddPane( m_messagePanel,
wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom().Layer(10) );
m_auimgr.Update(); m_auimgr.Update();
@ -548,12 +548,14 @@ void LIB_EDIT_FRAME::OnUpdatePinByPin( wxUpdateUIEvent& event )
event.Check( m_editPinsPerPartOrConvert ); event.Check( m_editPinsPerPartOrConvert );
} }
void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event ) void LIB_EDIT_FRAME::OnUpdatePinTable( wxUpdateUIEvent& event )
{ {
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
event.Enable( part != NULL ); event.Enable( part != NULL );
} }
void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event ) void LIB_EDIT_FRAME::OnUpdatePartNumber( wxUpdateUIEvent& event )
{ {
if( m_partSelectBox == NULL ) if( m_partSelectBox == NULL )
@ -642,7 +644,7 @@ void LIB_EDIT_FRAME::OnViewEntryDoc( wxCommandEvent& event )
wxString fileName; wxString fileName;
LIB_ALIAS* alias = part->GetAlias( m_aliasName ); LIB_ALIAS* alias = part->GetAlias( m_aliasName );
wxCHECK_RET( alias != NULL, wxT( "Alias not found." ) ); wxCHECK_RET( alias != NULL, "Alias not found." );
fileName = alias->GetDocFileName(); fileName = alias->GetDocFileName();
@ -669,6 +671,46 @@ void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event )
} }
void LIB_EDIT_FRAME::OnSaveCurrentPart( wxCommandEvent& aEvent )
{
LIB_PART* part = GetCurPart();
if( !part )
{
DisplayError( this, _( "No part to save." ) );
return;
}
PART_LIB* lib = GetCurLib();
if( !lib )
SelectActiveLibrary();
lib = GetCurLib();
if( !lib )
{
DisplayError( this, _( "No library specified." ) );
return;
}
try
{
SaveOnePart( lib );
}
catch( ... )
{
wxString msg;
msg.Printf( _( "Unexpected error occured saving symbol '%s' to symbol library '%s'." ),
part->GetName(), lib->GetName() );
DisplayError( this, msg );
return;
}
refreshSchematic();
}
void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
{ {
int id = event.GetId(); int id = event.GetId();
@ -712,7 +754,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
default: default:
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(),
wxEmptyString ); wxEmptyString );
break; break;
} }
@ -727,33 +769,6 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
SelectActiveLibrary(); SelectActiveLibrary();
break; break;
case ID_LIBEDIT_SAVE_CURRENT_PART:
{
LIB_PART* part = GetCurPart();
if( !part )
{
DisplayError( this, _( "No part to save." ) );
break;
}
PART_LIB* lib = GetCurLib();
if( !lib )
SelectActiveLibrary();
lib = GetCurLib();
if( !lib )
{
DisplayError( this, _( "No library specified." ) );
break;
}
SaveOnePart( lib );
}
break;
case ID_LIBEDIT_EDIT_PIN_BY_PIN: case ID_LIBEDIT_EDIT_PIN_BY_PIN:
m_editPinsPerPartOrConvert = m_mainToolBar->GetToolToggled( ID_LIBEDIT_EDIT_PIN_BY_PIN ); m_editPinsPerPartOrConvert = m_mainToolBar->GetToolToggled( ID_LIBEDIT_EDIT_PIN_BY_PIN );
break; break;
@ -931,7 +946,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
default: default:
DisplayError( this, wxT( "LIB_EDIT_FRAME::Process_Special_Functions error" ) ); DisplayError( this, "LIB_EDIT_FRAME::Process_Special_Functions error" );
break; break;
} }
@ -1058,8 +1073,8 @@ void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem )
// Display new text // Display new text
if( DC && !DrawItem->InEditMode() ) if( DC && !DrawItem->InEditMode() )
DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE, NULL, DrawItem->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_DEFAULT_DRAWMODE,
DefaultTransform ); NULL, DefaultTransform );
} }
@ -1092,7 +1107,7 @@ void LIB_EDIT_FRAME::OnCreateNewPartFromExisting( wxCommandEvent& event )
{ {
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
wxCHECK_RET( part, wxT( "Cannot create new part from non-existent current part." ) ); wxCHECK_RET( part, "Cannot create new part from non-existent current part." );
INSTALL_UNBUFFERED_DC( dc, m_canvas ); INSTALL_UNBUFFERED_DC( dc, m_canvas );
m_canvas->CrossHairOff( &dc ); m_canvas->CrossHairOff( &dc );
@ -1292,7 +1307,7 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF
if( item == NULL ) if( item == NULL )
{ {
wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS, wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS,
wxT( "Select item clarification context menu size limit exceeded." ) ); "Select item clarification context menu size limit exceeded." );
wxMenu selectMenu; wxMenu selectMenu;
AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ), AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ),
@ -1334,7 +1349,7 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF
void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
{ {
wxCHECK_RET( m_drawItem != NULL, wxT( "No drawing item selected to delete." ) ); wxCHECK_RET( m_drawItem != NULL, "No drawing item selected to delete." );
m_canvas->CrossHairOff( aDC ); m_canvas->CrossHairOff( aDC );
@ -1401,6 +1416,7 @@ void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
} }
} }
void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
{ {
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
@ -1413,6 +1429,7 @@ void LIB_EDIT_FRAME::OnOpenPinTable( wxCommandEvent& aEvent )
return; return;
} }
bool LIB_EDIT_FRAME::SynchronizePins() bool LIB_EDIT_FRAME::SynchronizePins()
{ {
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
@ -1420,3 +1437,19 @@ bool LIB_EDIT_FRAME::SynchronizePins()
return !m_editPinsPerPartOrConvert && ( part && return !m_editPinsPerPartOrConvert && ( part &&
( part->HasConversion() || part->IsMulti() ) ); ( part->HasConversion() || part->IsMulti() ) );
} }
void LIB_EDIT_FRAME::refreshSchematic() const
{
// This is not the most effecient way to do this because the changed library may not have
// any effect on the schematic symbol links. Since this is not called very often, take the
// hit here rather than the myriad other places (including SCH_SCREEN::Draw()) where it was
// being called.
SCH_SCREENS schematic;
schematic.UpdateSymbolLinks();
// There may be no parent window so use KIWAY message to refresh the schematic editor
// in case any symbols have changed.
Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_REFRESH, std::string( "" ), this );
}

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2014 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2014 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -281,6 +281,8 @@ public:
void OnOpenPinTable( wxCommandEvent& aEvent ); void OnOpenPinTable( wxCommandEvent& aEvent );
void OnSaveCurrentPart( wxCommandEvent& aEvent );
void OnUpdateSelectTool( wxUpdateUIEvent& aEvent ); void OnUpdateSelectTool( wxUpdateUIEvent& aEvent );
void OnUpdateEditingPart( wxUpdateUIEvent& event ); void OnUpdateEditingPart( wxUpdateUIEvent& event );
void OnUpdateNotEditingPart( wxUpdateUIEvent& event ); void OnUpdateNotEditingPart( wxUpdateUIEvent& event );
@ -606,6 +608,8 @@ private:
const KICAD_T aFilterList[] = LIB_COLLECTOR::AllItems ); const KICAD_T aFilterList[] = LIB_COLLECTOR::AllItems );
void EditField( LIB_FIELD* Field ); void EditField( LIB_FIELD* Field );
void refreshSchematic() const;
public: public:
/** /**
* Function LoadComponentAndSelectLib * Function LoadComponentAndSelectLib

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2017 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -141,7 +141,7 @@ void LIB_EDIT_FRAME::ReCreateHToolbar()
_( "Create a new component from the current one" ) ); _( "Create a new component from the current one" ) );
m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_CURRENT_PART, wxEmptyString, m_mainToolBar->AddTool( ID_LIBEDIT_SAVE_CURRENT_PART, wxEmptyString,
KiBitmap( save_part_in_mem_xpm ), KiBitmap( save_part_in_mem_xpm ),
_( "Update current component in current library" ) ); _( "Update current component in current library" ) );
m_mainToolBar->AddTool( ImportPartId, wxEmptyString, KiBitmap( import_xpm ), m_mainToolBar->AddTool( ImportPartId, wxEmptyString, KiBitmap( import_xpm ),