Browse Source

Fix parsing of Altium overbar notation.

Use the AltiumPinNamesToKiCad() algorithm for all conversions,
but don't do any conversions on plain text (RECORD=4).

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19080
pcb_db
Jeff Young 1 year ago
parent
commit
756f0c5027
  1. 3
      common/io/altium/altium_ascii_parser.cpp
  2. 3
      common/io/altium/altium_binary_parser.cpp
  3. 106
      common/io/altium/altium_parser_utils.cpp

3
common/io/altium/altium_ascii_parser.cpp

@ -117,7 +117,8 @@ std::map<wxString, wxString> ALTIUM_ASCII_PARSER::ReadProperties()
if( canonicalKey == wxT( "DESIGNATOR" ) || canonicalKey == wxT( "NAME" )
|| canonicalKey == wxT( "TEXT" ) )
{
value = AltiumPropertyToKiCadString( value );
if( kv[ wxT( "RECORD" ) ] != wxT( "4" ) )
value = AltiumPropertyToKiCadString( value );
}
}

3
common/io/altium/altium_binary_parser.cpp

@ -432,7 +432,8 @@ std::map<wxString, wxString> ALTIUM_BINARY_PARSER::ReadProperties(
|| canonicalKey == wxT( "NAME" )
|| canonicalKey == wxT( "TEXT" ) )
{
value = AltiumPropertyToKiCadString( value.Trim() );
if( kv[ wxT( "RECORD" ) ] != wxT( "4" ) )
value = AltiumPropertyToKiCadString( value.Trim() );
}
kv.insert( { canonicalKey, value.Trim() } );

106
common/io/altium/altium_parser_utils.cpp

@ -45,40 +45,52 @@ LIB_ID AltiumToKiCadLibID( const wxString& aLibName, const wxString& aLibReferen
wxString AltiumPropertyToKiCadString( const wxString& aString )
{
wxString converted;
bool inOverbar = false;
wxString output;
wxString tempString;
bool hasPrev = false;
wxUniChar prev;
for( wxString::const_iterator chIt = aString.begin(); chIt != aString.end(); ++chIt )
for( wxString::const_iterator it = aString.begin(); it != aString.end(); ++it )
{
wxString::const_iterator lookahead = chIt + 1;
char ch = 0;
if( lookahead != aString.end() && *lookahead == '\\' )
if( (*it).GetAsChar( &ch ) )
{
if( !inOverbar )
if( ch == '\\' )
{
converted += "~{";
inOverbar = true;
}
if( hasPrev )
{
tempString += prev;
hasPrev = false;
}
converted += *chIt;
chIt = lookahead;
continue; // Backslash is ignored and not added to the output
}
}
else
if( hasPrev ) // Two letters in a row with no backslash
{
if( inOverbar )
if( !tempString.empty() )
{
converted += "}";
inOverbar = false;
output += "~{" + tempString + "}";
tempString.Clear();
}
converted += *chIt;
output += prev;
}
prev = *it;
hasPrev = true;
}
if( inOverbar )
converted += "}";
// Append any leftover escaped string
if( !tempString.IsEmpty() )
output += "~{" + tempString + "}";
if( hasPrev )
output += prev;
return converted;
return output;
}
@ -148,9 +160,7 @@ wxString AltiumPcbSpecialStringsToKiCadStrings( const wxString&
const std::map<wxString, wxString>& aOverrides )
{
if( aString.IsEmpty() )
{
return aString;
}
// special case: string starts with dot -> whole string is special string
if( aString.at( 0 ) == '.' )
@ -174,57 +184,15 @@ wxString AltiumPcbSpecialStringsToKiCadStrings( const wxString&
wxString AltiumPinNamesToKiCad( wxString& aString )
{
wxString output;
wxString tempString;
bool hasPrev = false;
wxUniChar prev;
for( wxString::const_iterator it = aString.begin(); it != aString.end(); ++it )
{
char ch = 0;
if( (*it).GetAsChar( &ch ) )
{
if( ch == '\\' )
{
if( hasPrev )
{
tempString += prev;
hasPrev = false;
}
continue; // Backslash is ignored and not added to the output
}
}
if( hasPrev ) // Two letters in a row with no backslash
{
if( !tempString.empty() )
{
output += "~{" + tempString + "}";
tempString.Clear();
}
if( aString.IsEmpty() )
return wxEmptyString;
output += prev;
}
wxString rest;
prev = *it;
hasPrev = true;
}
if( aString.StartsWith( '\\', &rest ) && !rest.Contains( '\\' ) )
return "~{" + rest + "}";
// Append any leftover escaped string
if( !tempString.IsEmpty() )
{
output += "~{" + tempString + "}";
}
if( hasPrev )
{
output += prev;
}
return output;
return AltiumPropertyToKiCadString( aString );
}
VECTOR2I AltiumGetEllipticalPos( double aMajor, double aMinor, double aAngleRadians )

Loading…
Cancel
Save