Replace illegal characters in LIB_{ALIAS,PART} LIB_IDs

Schematic components have illegal characters replaced during load,
leading to broken component-symbol links. To avoid this, library symbols
should have their names fixed in the same way.

Fixes: lp:1752419
* https://bugs.launchpad.net/kicad/+bug/1752419
This commit is contained in:
Maciej Suminski 2018-03-06 11:09:11 +01:00
parent dfc47464d7
commit a5844c9bb8
3 changed files with 27 additions and 14 deletions

View File

@ -35,6 +35,7 @@
#include <gr_basic.h>
#include <sch_screen.h>
#include <richio.h>
#include <kicad_string.h>
#include <general.h>
#include <template_fieldnames.h>
@ -67,7 +68,7 @@ LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_PART* aRootPart ):
EDA_ITEM( LIB_ALIAS_T ),
shared( aRootPart )
{
name = aName;
SetName( aName );
}
@ -118,6 +119,13 @@ PART_LIB* LIB_ALIAS::GetLib()
}
void LIB_ALIAS::SetName( const wxString& aName )
{
name = aName;
ReplaceIllegalFileNameChars( name, '_' );
}
bool LIB_ALIAS::operator==( const wxChar* aName ) const
{
return name == aName;
@ -275,21 +283,22 @@ const wxString& LIB_PART::GetName() const
void LIB_PART::SetName( const wxString& aName )
{
m_libId.SetLibItemName( aName, false );
// The LIB_ALIAS that is the LIB_PART name has to be created so create it.
if( m_aliases.size() == 0 )
if( m_aliases.empty() )
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
else
m_aliases[0]->SetName( aName );
// LIB_ALIAS validates the name, reuse it instead of validating the name again
wxString validatedName( m_aliases[0]->GetName() );
m_libId.SetLibItemName( validatedName, false );
LIB_FIELD& valueField = GetValueField();
// LIB_FIELD::SetText() calls LIB_PART::SetName(),
// the following if-clause is to break an infinite loop
if( valueField.GetText() != aName )
valueField.SetText( aName );
if( valueField.GetText() != validatedName )
valueField.SetText( validatedName );
}

View File

@ -125,7 +125,7 @@ public:
const wxString& GetName() const { return name; }
void SetName( const wxString& aName ) { name = aName; }
void SetName( const wxString& aName );
void SetDescription( const wxString& aDescription )
{

View File

@ -504,26 +504,30 @@ void LIB_FIELD::SetText( const wxString& aText )
if( aText == GetText() )
return;
wxString oldName = m_Text;
wxString oldValue( m_Text );
wxString newValue( aText );
if( m_id == VALUE && m_Parent != NULL )
{
LIB_PART* parent = GetParent();
LIB_PART* parent = GetParent();
// Set the parent component and root alias to the new name.
if( parent->GetName().CmpNoCase( aText ) != 0 )
parent->SetName( aText );
{
ReplaceIllegalFileNameChars( newValue, '_' );
parent->SetName( newValue );
}
}
if( InEditMode() )
{
m_Text = oldName;
m_savedText = aText;
m_Text = oldValue;
m_savedText = newValue;
m_updateText = true;
}
else
{
m_Text = aText;
m_Text = newValue;
}
}