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:
parent
dfc47464d7
commit
a5844c9bb8
|
@ -35,6 +35,7 @@
|
||||||
#include <gr_basic.h>
|
#include <gr_basic.h>
|
||||||
#include <sch_screen.h>
|
#include <sch_screen.h>
|
||||||
#include <richio.h>
|
#include <richio.h>
|
||||||
|
#include <kicad_string.h>
|
||||||
|
|
||||||
#include <general.h>
|
#include <general.h>
|
||||||
#include <template_fieldnames.h>
|
#include <template_fieldnames.h>
|
||||||
|
@ -67,7 +68,7 @@ LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_PART* aRootPart ):
|
||||||
EDA_ITEM( LIB_ALIAS_T ),
|
EDA_ITEM( LIB_ALIAS_T ),
|
||||||
shared( aRootPart )
|
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
|
bool LIB_ALIAS::operator==( const wxChar* aName ) const
|
||||||
{
|
{
|
||||||
return name == aName;
|
return name == aName;
|
||||||
|
@ -275,21 +283,22 @@ const wxString& LIB_PART::GetName() const
|
||||||
|
|
||||||
void LIB_PART::SetName( const wxString& aName )
|
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.
|
// 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 ) );
|
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
|
||||||
else
|
else
|
||||||
m_aliases[0]->SetName( aName );
|
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& valueField = GetValueField();
|
||||||
|
|
||||||
// LIB_FIELD::SetText() calls LIB_PART::SetName(),
|
// LIB_FIELD::SetText() calls LIB_PART::SetName(),
|
||||||
// the following if-clause is to break an infinite loop
|
// the following if-clause is to break an infinite loop
|
||||||
if( valueField.GetText() != aName )
|
if( valueField.GetText() != validatedName )
|
||||||
valueField.SetText( aName );
|
valueField.SetText( validatedName );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ public:
|
||||||
|
|
||||||
const wxString& GetName() const { return name; }
|
const wxString& GetName() const { return name; }
|
||||||
|
|
||||||
void SetName( const wxString& aName ) { name = aName; }
|
void SetName( const wxString& aName );
|
||||||
|
|
||||||
void SetDescription( const wxString& aDescription )
|
void SetDescription( const wxString& aDescription )
|
||||||
{
|
{
|
||||||
|
|
|
@ -504,7 +504,8 @@ void LIB_FIELD::SetText( const wxString& aText )
|
||||||
if( aText == GetText() )
|
if( aText == GetText() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxString oldName = m_Text;
|
wxString oldValue( m_Text );
|
||||||
|
wxString newValue( aText );
|
||||||
|
|
||||||
if( m_id == VALUE && m_Parent != NULL )
|
if( m_id == VALUE && m_Parent != NULL )
|
||||||
{
|
{
|
||||||
|
@ -512,18 +513,21 @@ void LIB_FIELD::SetText( const wxString& aText )
|
||||||
|
|
||||||
// Set the parent component and root alias to the new name.
|
// Set the parent component and root alias to the new name.
|
||||||
if( parent->GetName().CmpNoCase( aText ) != 0 )
|
if( parent->GetName().CmpNoCase( aText ) != 0 )
|
||||||
parent->SetName( aText );
|
{
|
||||||
|
ReplaceIllegalFileNameChars( newValue, '_' );
|
||||||
|
parent->SetName( newValue );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( InEditMode() )
|
if( InEditMode() )
|
||||||
{
|
{
|
||||||
m_Text = oldName;
|
m_Text = oldValue;
|
||||||
m_savedText = aText;
|
m_savedText = newValue;
|
||||||
m_updateText = true;
|
m_updateText = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Text = aText;
|
m_Text = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue