Altium schematic: fix properties parsing in old formats.

Leading "|" can be missing before "RECORD=28" in old formats.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16513
This commit is contained in:
Alex Shvartzkop 2024-01-14 13:12:47 +03:00
parent 42d8c85f12
commit b7460f29b4
4 changed files with 22 additions and 9 deletions

View File

@ -441,8 +441,20 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties(
while( token_end < str.size() && token_end != std::string::npos )
{
std::size_t token_start = str.find( '|', token_end );
std::size_t token_equal = str.find( '=', token_start );
token_end = str.find( '|', token_start + 1 );
std::size_t token_equal = str.find( '=', token_end );
std::size_t key_start;
if( token_start <= token_equal )
{
key_start = token_start + 1;
}
else
{
// Leading "|" before "RECORD=28" may be missing in older schematic versions.
key_start = token_end;
}
token_end = str.find( '|', key_start );
if( token_equal >= token_end )
{
@ -454,7 +466,7 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties(
token_end = str.size() + 1; // this is the correct offset
}
std::string keyS = str.substr( token_start + 1, token_equal - token_start - 1 );
std::string keyS = str.substr( key_start, token_equal - key_start );
std::string valueS = str.substr( token_equal + 1, token_end - token_equal - 1 );
// convert the strings to wxStrings, since we use them everywhere

View File

@ -36,7 +36,7 @@
ALTIUM_SCH_RECORD ReadRecord( const std::map<wxString, wxString>& aProps )
{
int recordId = ALTIUM_PARSER::ReadInt( aProps, "RECORD", 0 );
int recordId = ALTIUM_PARSER::ReadInt( aProps, "RECORD", -1 );
return static_cast<ALTIUM_SCH_RECORD>( recordId );
}

View File

@ -56,6 +56,8 @@ struct ASCH_ADDITIONAL_FILE
enum class ALTIUM_SCH_RECORD
{
UNKNOWN = -1,
HEADER = 0,
COMPONENT = 1,
PIN = 2,

View File

@ -631,11 +631,10 @@ void SCH_IO_ALTIUM::ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile
{
std::map<wxString, wxString> properties = reader.ReadProperties();
int recordId = ALTIUM_PARSER::ReadInt( properties, "RECORD", 0 );
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
wxString libtype = ALTIUM_PARSER::ReadString( properties, "HEADER", "" );
if( record != ALTIUM_SCH_RECORD::HEADER )
THROW_IO_ERROR( "Header expected" );
if( libtype.CmpNoCase( "Protel for Windows - Schematic Capture Binary File Version 5.0" ) )
THROW_IO_ERROR( _( "Expected Altium Schematic file version 5.0" ) );
}
// Prepare some local variables
@ -649,7 +648,7 @@ void SCH_IO_ALTIUM::ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile
{
std::map<wxString, wxString> properties = reader.ReadProperties();
int recordId = ALTIUM_PARSER::ReadInt( properties, "RECORD", 0 );
int recordId = ALTIUM_PARSER::ReadInt( properties, "RECORD", -1 );
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
// see: https://github.com/vadmium/python-altium/blob/master/format.md