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:
parent
42d8c85f12
commit
b7460f29b4
|
@ -441,8 +441,20 @@ std::map<wxString, wxString> ALTIUM_PARSER::ReadProperties(
|
||||||
while( token_end < str.size() && token_end != std::string::npos )
|
while( token_end < str.size() && token_end != std::string::npos )
|
||||||
{
|
{
|
||||||
std::size_t token_start = str.find( '|', token_end );
|
std::size_t token_start = str.find( '|', token_end );
|
||||||
std::size_t token_equal = str.find( '=', token_start );
|
std::size_t token_equal = str.find( '=', token_end );
|
||||||
token_end = str.find( '|', token_start + 1 );
|
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 )
|
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
|
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 );
|
std::string valueS = str.substr( token_equal + 1, token_end - token_equal - 1 );
|
||||||
|
|
||||||
// convert the strings to wxStrings, since we use them everywhere
|
// convert the strings to wxStrings, since we use them everywhere
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
ALTIUM_SCH_RECORD ReadRecord( const std::map<wxString, wxString>& aProps )
|
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 );
|
return static_cast<ALTIUM_SCH_RECORD>( recordId );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,8 @@ struct ASCH_ADDITIONAL_FILE
|
||||||
|
|
||||||
enum class ALTIUM_SCH_RECORD
|
enum class ALTIUM_SCH_RECORD
|
||||||
{
|
{
|
||||||
|
UNKNOWN = -1,
|
||||||
|
|
||||||
HEADER = 0,
|
HEADER = 0,
|
||||||
COMPONENT = 1,
|
COMPONENT = 1,
|
||||||
PIN = 2,
|
PIN = 2,
|
||||||
|
|
|
@ -631,11 +631,10 @@ void SCH_IO_ALTIUM::ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile
|
||||||
{
|
{
|
||||||
std::map<wxString, wxString> properties = reader.ReadProperties();
|
std::map<wxString, wxString> properties = reader.ReadProperties();
|
||||||
|
|
||||||
int recordId = ALTIUM_PARSER::ReadInt( properties, "RECORD", 0 );
|
wxString libtype = ALTIUM_PARSER::ReadString( properties, "HEADER", "" );
|
||||||
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
|
||||||
|
|
||||||
if( record != ALTIUM_SCH_RECORD::HEADER )
|
if( libtype.CmpNoCase( "Protel for Windows - Schematic Capture Binary File Version 5.0" ) )
|
||||||
THROW_IO_ERROR( "Header expected" );
|
THROW_IO_ERROR( _( "Expected Altium Schematic file version 5.0" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare some local variables
|
// 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();
|
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 );
|
ALTIUM_SCH_RECORD record = static_cast<ALTIUM_SCH_RECORD>( recordId );
|
||||||
|
|
||||||
// see: https://github.com/vadmium/python-altium/blob/master/format.md
|
// see: https://github.com/vadmium/python-altium/blob/master/format.md
|
||||||
|
|
Loading…
Reference in New Issue