eeschema: Rescue symbols with illegal chars
When parsing component names, we need to account for the possibility of illegal characters (e.g. "/", ":") in the names from v4 libraries. They are fixed internally by the cache parser but if we don't fix them in the rescue routine, the symbol won't match it's cache name. This standardizes all schematic illegal character routines into LIB_ID Fixes: lp:1774774 * https://bugs.launchpad.net/kicad/+bug/1774774
This commit is contained in:
parent
7eea8f808d
commit
d30ac2967a
|
@ -371,14 +371,17 @@ bool LIB_ID::HasIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType )
|
UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool aLib )
|
||||||
{
|
{
|
||||||
UTF8 fixedName;
|
UTF8 fixedName;
|
||||||
|
|
||||||
for( UTF8::uni_iter chIt = aLibItemName.ubegin(); chIt < aLibItemName.uend(); ++chIt )
|
for( UTF8::uni_iter chIt = aLibItemName.ubegin(); chIt < aLibItemName.uend(); ++chIt )
|
||||||
{
|
{
|
||||||
auto ch = *chIt;
|
auto ch = *chIt;
|
||||||
fixedName += isLegalChar( ch, aType ) ? ch : '_';
|
if( aLib )
|
||||||
|
fixedName += isLegalLibNicknameChar( ch, aType ) ? ch : '_';
|
||||||
|
else
|
||||||
|
fixedName += isLegalChar( ch, aType ) ? ch : '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixedName;
|
return fixedName;
|
||||||
|
@ -386,15 +389,17 @@ UTF8 LIB_ID::FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType )
|
||||||
|
|
||||||
|
|
||||||
///> Set of characters not accepted library entry names.
|
///> Set of characters not accepted library entry names.
|
||||||
#define BASE_ILLEGAL_CHARS '\t', '\n', '\r', ':', '/', '\\'
|
#define BASE_ILLEGAL_CHARS '\t', '\n', '\r', '/', '\\'
|
||||||
const unsigned schIllegalChars[] = { BASE_ILLEGAL_CHARS, ' ' };
|
const unsigned schIllegalChars[] = { BASE_ILLEGAL_CHARS, ':', ' ' };
|
||||||
const unsigned pcbIllegalChars[] = { BASE_ILLEGAL_CHARS, 0 };
|
const unsigned schAliasIllegalChars[] = { BASE_ILLEGAL_CHARS, 0, 0 };
|
||||||
|
const unsigned pcbIllegalChars[] = { BASE_ILLEGAL_CHARS, ':', 0 };
|
||||||
#define ILL_CHAR_SIZE (sizeof(schIllegalChars) / sizeof(int))
|
#define ILL_CHAR_SIZE (sizeof(schIllegalChars) / sizeof(int))
|
||||||
|
|
||||||
bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
|
bool LIB_ID::isLegalChar( unsigned aUniChar, LIB_ID_TYPE aType )
|
||||||
{
|
{
|
||||||
const unsigned (&illegalChars)[ILL_CHAR_SIZE] =
|
const unsigned (&illegalChars)[ILL_CHAR_SIZE] =
|
||||||
aType == ID_SCH ? schIllegalChars : pcbIllegalChars;
|
aType == ID_SCH ? schIllegalChars :
|
||||||
|
aType == ID_ALIAS ? schAliasIllegalChars : pcbIllegalChars;
|
||||||
|
|
||||||
for( const unsigned ch : illegalChars )
|
for( const unsigned ch : illegalChars )
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,24 +119,10 @@ PART_LIB* LIB_ALIAS::GetLib()
|
||||||
|
|
||||||
void LIB_ALIAS::SetName( const wxString& aName )
|
void LIB_ALIAS::SetName( const wxString& aName )
|
||||||
{
|
{
|
||||||
name = aName;
|
name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_ALIAS );
|
||||||
ValidateName( name );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LIB_ALIAS::ValidateName( wxString& aName )
|
|
||||||
{
|
|
||||||
// they are same as illegal filename chars, but the ':' is allowed
|
|
||||||
// only because it is used to create symbol names in lib cache
|
|
||||||
static const wxString illegalSymbolNameChars( "\\/\"<>|" );
|
|
||||||
|
|
||||||
for( wxString::iterator it = aName.begin(); it != aName.end(); ++it )
|
|
||||||
{
|
|
||||||
if( illegalSymbolNameChars.Find( *it ) != wxNOT_FOUND )
|
|
||||||
*it = '_';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool LIB_ALIAS::operator==( const wxChar* aName ) const
|
bool LIB_ALIAS::operator==( const wxChar* aName ) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -569,15 +569,6 @@ bool LIB_MANAGER::LibraryExists( const wxString& aLibrary, bool aCheckEnabled )
|
||||||
return symTable()->HasLibrary( aLibrary, aCheckEnabled );
|
return symTable()->HasLibrary( aLibrary, aCheckEnabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString LIB_MANAGER::ValidateName( const wxString& aName )
|
|
||||||
{
|
|
||||||
wxString name( aName );
|
|
||||||
name.Replace( " ", "_" );
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
wxString LIB_MANAGER::GetUniqueLibraryName() const
|
wxString LIB_MANAGER::GetUniqueLibraryName() const
|
||||||
{
|
{
|
||||||
wxString name = "New_Library";
|
wxString name = "New_Library";
|
||||||
|
|
|
@ -217,11 +217,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool RevertLibrary( const wxString& aLibrary );
|
bool RevertLibrary( const wxString& aLibrary );
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces all characters considered illegal in library/part names with underscores.
|
|
||||||
*/
|
|
||||||
static wxString ValidateName( const wxString& aName );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a library name that is not currently in use.
|
* Returns a library name that is not currently in use.
|
||||||
* Used for generating names for new libraries.
|
* Used for generating names for new libraries.
|
||||||
|
|
|
@ -65,7 +65,7 @@ void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
newFieldValue = dlg.GetText();
|
newFieldValue = dlg.GetText();
|
||||||
LIB_ALIAS::ValidateName( newFieldValue );
|
LIB_ID::FixIllegalChars( newFieldValue, LIB_ID::ID_SCH );
|
||||||
wxString oldFieldValue = aField->GetFullText( m_unit );
|
wxString oldFieldValue = aField->GetFullText( m_unit );
|
||||||
bool renamed = aField->GetId() == VALUE && newFieldValue != oldFieldValue;
|
bool renamed = aField->GetId() == VALUE && newFieldValue != oldFieldValue;
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ static void get_components( std::vector<SCH_COMPONENT*>& aComponents )
|
||||||
static LIB_PART* find_component( const wxString& aName, PART_LIBS* aLibs, bool aCached )
|
static LIB_PART* find_component( const wxString& aName, PART_LIBS* aLibs, bool aCached )
|
||||||
{
|
{
|
||||||
LIB_PART *part = NULL;
|
LIB_PART *part = NULL;
|
||||||
|
wxString new_name = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_SCH );
|
||||||
|
|
||||||
for( PART_LIB& each_lib : *aLibs )
|
for( PART_LIB& each_lib : *aLibs )
|
||||||
{
|
{
|
||||||
|
@ -103,7 +104,7 @@ static LIB_PART* find_component( const wxString& aName, PART_LIBS* aLibs, bool a
|
||||||
if( !aCached && each_lib.IsCache() )
|
if( !aCached && each_lib.IsCache() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
part = each_lib.FindPart( aName );
|
part = each_lib.FindPart( new_name );
|
||||||
|
|
||||||
if( part )
|
if( part )
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <class_library.h>
|
#include <class_library.h>
|
||||||
#include <class_libentry.h>
|
#include <class_libentry.h>
|
||||||
#include <lib_draw_item.h>
|
#include <lib_draw_item.h>
|
||||||
|
#include <lib_id.h>
|
||||||
#include <sch_component.h>
|
#include <sch_component.h>
|
||||||
#include <sch_sheet_path.h>
|
#include <sch_sheet_path.h>
|
||||||
#include <lib_arc.h>
|
#include <lib_arc.h>
|
||||||
|
@ -134,8 +135,7 @@ wxString SCH_EAGLE_PLUGIN::getLibName()
|
||||||
m_libName = "noname";
|
m_libName = "noname";
|
||||||
|
|
||||||
m_libName += "-eagle-import";
|
m_libName += "-eagle-import";
|
||||||
// use ID_SCH as it is more restrictive
|
m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH, true );
|
||||||
m_libName = LIB_ID::FixIllegalChars( m_libName, LIB_ID::ID_SCH );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_libName;
|
return m_libName;
|
||||||
|
@ -1064,22 +1064,20 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
|
||||||
wxString gatename = epart->deviceset + epart->device + einstance.gate;
|
wxString gatename = epart->deviceset + epart->device + einstance.gate;
|
||||||
wxString symbolname = wxString( epart->deviceset + epart->device );
|
wxString symbolname = wxString( epart->deviceset + epart->device );
|
||||||
symbolname.Replace( "*", "" );
|
symbolname.Replace( "*", "" );
|
||||||
LIB_ALIAS::ValidateName( symbolname );
|
wxString kisymbolname = LIB_ID::FixIllegalChars( symbolname, LIB_ID::ID_SCH );
|
||||||
|
|
||||||
int unit = m_eagleLibs[libraryname].GateUnit[gatename];
|
int unit = m_eagleLibs[libraryname].GateUnit[gatename];
|
||||||
|
|
||||||
wxString package;
|
wxString package;
|
||||||
EAGLE_LIBRARY* elib = &m_eagleLibs[libraryname];
|
EAGLE_LIBRARY* elib = &m_eagleLibs[libraryname];
|
||||||
|
|
||||||
auto p = elib->package.find( symbolname );
|
auto p = elib->package.find( kisymbolname );
|
||||||
|
|
||||||
if( p != elib->package.end() )
|
if( p != elib->package.end() )
|
||||||
{
|
{
|
||||||
package = p->second;
|
package = p->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString kisymbolname = LIB_ID::FixIllegalChars( symbolname, LIB_ID::ID_SCH );
|
|
||||||
|
|
||||||
LIB_ALIAS* alias = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname,
|
LIB_ALIAS* alias = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname,
|
||||||
m_properties.get() );
|
m_properties.get() );
|
||||||
|
|
||||||
|
@ -1138,7 +1136,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
|
||||||
if( epart->value )
|
if( epart->value )
|
||||||
component->GetField( VALUE )->SetText( *epart->value );
|
component->GetField( VALUE )->SetText( *epart->value );
|
||||||
else
|
else
|
||||||
component->GetField( VALUE )->SetText( symbolname );
|
component->GetField( VALUE )->SetText( kisymbolname );
|
||||||
|
|
||||||
// Set the visibility of fields.
|
// Set the visibility of fields.
|
||||||
component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() );
|
component->GetField( REFERENCE )->SetVisible( part->GetField( REFERENCE )->IsVisible() );
|
||||||
|
@ -1262,7 +1260,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode,
|
||||||
wxString symbolName = edeviceset.name + edevice.name;
|
wxString symbolName = edeviceset.name + edevice.name;
|
||||||
symbolName.Replace( "*", "" );
|
symbolName.Replace( "*", "" );
|
||||||
wxASSERT( !symbolName.IsEmpty() );
|
wxASSERT( !symbolName.IsEmpty() );
|
||||||
LIB_ALIAS::ValidateName( symbolName );
|
symbolName = LIB_ID::FixIllegalChars( symbolName, LIB_ID::ID_SCH );
|
||||||
|
|
||||||
if( edevice.package )
|
if( edevice.package )
|
||||||
aEagleLibrary->package[symbolName] = edevice.package.Get();
|
aEagleLibrary->package[symbolName] = edevice.package.Get();
|
||||||
|
|
|
@ -2417,7 +2417,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs()
|
||||||
SCH_PARSE_ERROR( "$CMP command expected", reader, line );
|
SCH_PARSE_ERROR( "$CMP command expected", reader, line );
|
||||||
|
|
||||||
parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
|
parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
|
||||||
LIB_ALIAS::ValidateName( aliasName );
|
LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_ALIAS );
|
||||||
LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
|
LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
|
||||||
|
|
||||||
if( it == m_aliases.end() )
|
if( it == m_aliases.end() )
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
LIB_ID( const wxString& aId );
|
LIB_ID( const wxString& aId );
|
||||||
|
|
||||||
///> Types of library identifiers
|
///> Types of library identifiers
|
||||||
enum LIB_ID_TYPE { ID_SCH, ID_PCB };
|
enum LIB_ID_TYPE { ID_SCH, ID_ALIAS, ID_PCB };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This LIB_ID ctor is a special version which ignores the parsing due to symbol
|
* This LIB_ID ctor is a special version which ignores the parsing due to symbol
|
||||||
|
@ -218,9 +218,10 @@ public:
|
||||||
*
|
*
|
||||||
* @param aLibItemName is the #LIB_ID item name to replace illegal characters.
|
* @param aLibItemName is the #LIB_ID item name to replace illegal characters.
|
||||||
* @param aType is the library identifier type
|
* @param aType is the library identifier type
|
||||||
|
* @param aLib True if we are checking library names, false if we are checking item names
|
||||||
* @return the corrected version of \a aLibItemName.
|
* @return the corrected version of \a aLibItemName.
|
||||||
*/
|
*/
|
||||||
static UTF8 FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType );
|
static UTF8 FixIllegalChars( const UTF8& aLibItemName, LIB_ID_TYPE aType, bool aLib = false );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks for characters that are illegal in library nicknames.
|
* Looks for characters that are illegal in library nicknames.
|
||||||
|
|
Loading…
Reference in New Issue