altium: special string override map should be case-insensitive

This only fixes overrides where we explicitly map an override. Wrongly written variables pointing to fields are not corrected by this.

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/6256
This commit is contained in:
Thomas Pointhuber 2021-03-20 20:41:51 +01:00
parent 3bf5c814e1
commit d9229697d8
4 changed files with 31 additions and 10 deletions

View File

@ -42,8 +42,8 @@ LIB_ID AltiumToKiCadLibID( wxString aLibName, wxString aLibReference )
}
// https://www.altium.com/documentation/altium-designer/sch-obj-textstringtext-string-ad#!special-strings
wxString AltiumSpecialStringsToKiCadVariables( const wxString& aString,
const std::map<wxString, wxString>& aOverride )
wxString AltiumSpecialStringsToKiCadVariables( const wxString& aString,
const altium_override_map_t& aOverride )
{
if( aString.IsEmpty() || aString.at( 0 ) != '=' )
{

View File

@ -30,10 +30,22 @@
#include <kicad_string.h>
#include <lib_id.h>
#include <iostream>
struct CASE_INSENSITIVE_COMPARATOR
{
bool operator()( const wxString& s1, const wxString& s2 ) const
{
// Altium variables are case insensitive.
return s1.CmpNoCase( s2 ) < 0;
}
};
typedef std::map<wxString, wxString, CASE_INSENSITIVE_COMPARATOR> altium_override_map_t;
LIB_ID AltiumToKiCadLibID( wxString aLibName, wxString aLibReference );
wxString AltiumSpecialStringsToKiCadVariables( const wxString& aString,
const std::map<wxString, wxString>& aOverride );
wxString AltiumSpecialStringsToKiCadVariables( const wxString& aString,
const altium_override_map_t& aOverride );
#endif //ALTIUM_PARSER_UTILS_H

View File

@ -2052,7 +2052,7 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map<wxString, wxString>& aPro
ASCH_PARAMETER elem( aProperties );
// TODO: fill in replacements from variant, sheet and project
std::map<wxString, wxString> stringReplacement = {
altium_override_map_t stringReplacement = {
{ "Comment", "${VALUE}" },
{ "Value", "${Altium_Value}" },
};
@ -2102,7 +2102,7 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map<wxString, wxString>& aPro
else
{
int fieldIdx = component->GetFieldCount();
wxString fieldName = elem.name == "Value" ? "Altium_Value" : elem.name;
wxString fieldName = elem.name.IsSameAs( "Value", false ) ? "Altium_Value" : elem.name;
field = component->AddField( { position, fieldIdx, component, fieldName } );
}

View File

@ -44,9 +44,9 @@ BOOST_FIXTURE_TEST_SUITE( AltiumParserUtils, ALTIUM_PARSER_UTILS_FIXTURE )
struct SPECIAL_STRINGS_TO_KICAD
{
wxString input;
wxString exp_result;
std::map<wxString, wxString> override;
wxString input;
wxString exp_result;
altium_override_map_t override;
};
/**
@ -65,7 +65,6 @@ static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_prope
{ "A\tB", "A\tB", {} },
{ "This is a long text with spaces", "This is a long text with spaces", {} },
// Text format (underscore,...), TODO: add
// TODO: variable replacement is in fact case insensitive
// Escaping, TODO: add
{ "+", "+", {} },
{ "'", "'", {} },
@ -86,6 +85,16 @@ static const std::vector<SPECIAL_STRINGS_TO_KICAD> special_string_to_kicad_prope
{ "=A+B", "${A}${B}", {} },
{ "=A+B", "C${B}", { { "A", "C" } } },
{ "=A+B", "CD", { { "A", "C" }, { "B", "D" } } },
// Case insensitive special strings
{ "=A", "C", { { "a", "C" } } },
{ "=a", "C", { { "A", "C" } } },
{ "=AB", "C", { { "Ab", "C" } } },
{ "=AB", "C", { { "aB", "C" } } },
{ "=AB", "C", { { "ab", "C" } } },
{ "=AB", "C", { { "AB", "C" } } },
{ "=aB", "C", { { "Ab", "C" } } },
{ "=Ab", "C", { { "aB", "C" } } },
{ "=ab", "C", { { "AB", "C" } } },
// Special strings with text
{ "='A'", "A", {} },
{ "='This is a long text with spaces'", "This is a long text with spaces", {} },