diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 4f7f8807be..09bab9467c 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -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 ); } diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 79cfeecce7..3079690251 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -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 ) { diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 7acbf73280..a4af0c6ffa 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -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; } }