Minor symbol remapping fixes.

The remapping utility would create a new project specific library when a
symbolic link pointed to a library already defined in the symbol library
table.  Now the comparison checks to see if the library path and file
name are actually a symbolic link if the file names are not the same when
the symbol library table entry is a file name rather than a URL.  URLs
are simple string comparisons.

Disable the remap button after the remapping completed.

Remove some commented out code from the edit symbol in schematic dialog.

Fixes lp:1738634

https://bugs.launchpad.net/kicad/+bug/1738634
This commit is contained in:
Wayne Stambaugh 2017-12-18 18:25:34 -05:00
parent 992820f722
commit 8f0e6469ca
7 changed files with 40 additions and 30 deletions

View File

@ -25,6 +25,7 @@
#include <wx/filename.h>
#include <wx/uri.h>
#include <set>
@ -335,15 +336,24 @@ const LIB_TABLE_ROW* LIB_TABLE::FindRowByURI( const wxString& aURI )
for( unsigned i = 0; i < cur->rows.size(); i++ )
{
wxString uri = cur->rows[i].GetFullURI( true );
wxString tmp = cur->rows[i].GetFullURI( true );
if( wxFileName::GetPathSeparator() == wxChar( '\\' ) && uri.Find( wxChar( '/' ) ) >= 0 )
uri.Replace( "/", "\\" );
wxURI uri( tmp );
if( (wxFileName::IsCaseSensitive() && uri == aURI)
|| (!wxFileName::IsCaseSensitive() && uri.Upper() == aURI.Upper() ) )
if( uri.HasScheme() )
{
return &cur->rows[i]; // found
if( tmp == aURI )
return &cur->rows[i]; // found as URI
}
else
{
wxFileName fn = aURI;
// This will also test if the file is a symlink so if we are comparing
// a symlink to the same real file, the comparison will be true. See
// wxFileName::SameAs() in the wxWidgets source.
if( fn == wxFileName( tmp ) )
return &cur->rows[i]; // found as full path and file name
}
}

View File

@ -46,6 +46,8 @@
DIALOG_SYMBOL_REMAP::DIALOG_SYMBOL_REMAP( SCH_EDIT_FRAME* aParent ) :
DIALOG_SYMBOL_REMAP_BASE( aParent )
{
m_remapped = false;
wxString text;
text = _( "This schematic currently uses the symbol library list look up method for "
@ -90,6 +92,8 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent )
// Reload the the cache symbol library.
Prj().SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL );
Prj().SchLibs();
m_remapped = true;
}
@ -373,3 +377,8 @@ void DIALOG_SYMBOL_REMAP::backupProject()
}
}
void DIALOG_SYMBOL_REMAP::OnUpdateUIRemapButton( wxUpdateUIEvent& aEvent )
{
aEvent.Enable( !m_remapped );
}

View File

@ -41,6 +41,9 @@ public:
void OnRemapSymbols( wxCommandEvent& aEvent ) override;
protected:
void OnUpdateUIRemapButton( wxUpdateUIEvent& aEvent ) override;
private:
/**
* Add libraries found in the legacy library list to \a aLibs that are not found in
@ -75,6 +78,8 @@ private:
* - The rescue library (*-rescue.lib -> *.rescue.lib.v4) file.
*/
void backupProject();
bool m_remapped;
};
#endif // _DIALOG_SYMBOL_REMAP_H_

View File

@ -27,8 +27,8 @@ DIALOG_SYMBOL_REMAP_BASE::DIALOG_SYMBOL_REMAP_BASE( wxWindow* parent, wxWindowID
wxBoxSizer* bSizer3;
bSizer3 = new wxBoxSizer( wxVERTICAL );
m_buttonRemp = new wxButton( this, wxID_ANY, _("Remap Symbols"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer3->Add( m_buttonRemp, 0, wxALL|wxEXPAND, 5 );
m_buttonRemap = new wxButton( this, wxID_ANY, _("Remap Symbols"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer3->Add( m_buttonRemap, 0, wxALL|wxEXPAND, 5 );
m_buttonClose = new wxButton( this, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer3->Add( m_buttonClose, 0, wxALL|wxEXPAND, 5 );
@ -58,12 +58,14 @@ DIALOG_SYMBOL_REMAP_BASE::DIALOG_SYMBOL_REMAP_BASE( wxWindow* parent, wxWindowID
this->Centre( wxBOTH );
// Connect Events
m_buttonRemp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_REMAP_BASE::OnRemapSymbols ), NULL, this );
m_buttonRemap->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_REMAP_BASE::OnRemapSymbols ), NULL, this );
m_buttonRemap->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SYMBOL_REMAP_BASE::OnUpdateUIRemapButton ), NULL, this );
}
DIALOG_SYMBOL_REMAP_BASE::~DIALOG_SYMBOL_REMAP_BASE()
{
// Disconnect Events
m_buttonRemp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_REMAP_BASE::OnRemapSymbols ), NULL, this );
m_buttonRemap->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_REMAP_BASE::OnRemapSymbols ), NULL, this );
m_buttonRemap->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SYMBOL_REMAP_BASE::OnUpdateUIRemapButton ), NULL, this );
}

View File

@ -236,7 +236,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_buttonRemp</property>
<property name="name">m_buttonRemap</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -280,7 +280,7 @@
<event name="OnRightUp"></event>
<event name="OnSetFocus"></event>
<event name="OnSize"></event>
<event name="OnUpdateUI"></event>
<event name="OnUpdateUI">OnUpdateUIRemapButton</event>
</object>
</object>
<object class="sizeritem" expanded="1">

View File

@ -37,12 +37,13 @@ class DIALOG_SYMBOL_REMAP_BASE : public DIALOG_SHIM
protected:
wxHtmlWindow* m_htmlCtrl;
wxButton* m_buttonRemp;
wxButton* m_buttonRemap;
wxButton* m_buttonClose;
WX_HTML_REPORT_PANEL* m_messagePanel;
// Virtual event handlers, overide them in your derived class
virtual void OnRemapSymbols( wxCommandEvent& event ) { event.Skip(); }
virtual void OnUpdateUIRemapButton( wxUpdateUIEvent& event ) { event.Skip(); }
public:

View File

@ -53,23 +53,6 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
wxT( "Invalid schematic field parent item." ) );
// LIB_ID id = component->GetLibId();
// LIB_ALIAS* alias = NULL;
// try
// {
// alias = Prj().SchSymbolLibTable()->LoadSymbol( id );
// }
// catch( ... )
// {
// }
// LIB_PART* part = ( alias ) ? alias->GetPart() : NULL;
// wxCHECK_RET( part, wxString::Format( "Symbol '%s' not found in library '%s'",
// id.GetLibItemName().wx_str(),
// id.GetLibNickname().wx_str() ) );
// Save old component in undo list if not already in edit, or moving.
if( aField->GetFlags() == 0 )
SaveCopyInUndoList( component, UR_CHANGED );