Browse Source

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
6.0.7
Thomas Pointhuber 5 years ago
parent
commit
d9229697d8
  1. 4
      common/plugins/altium/altium_parser_utils.cpp
  2. 16
      common/plugins/altium/altium_parser_utils.h
  3. 4
      eeschema/sch_plugins/altium/sch_altium_plugin.cpp
  4. 17
      qa/common/plugins/altium/test_altium_parser_utils.cpp

4
common/plugins/altium/altium_parser_utils.cpp

@ -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 ) != '=' )
{

16
common/plugins/altium/altium_parser_utils.h

@ -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

4
eeschema/sch_plugins/altium/sch_altium_plugin.cpp

@ -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 } );
}

17
qa/common/plugins/altium/test_altium_parser_utils.cpp

@ -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", {} },

Loading…
Cancel
Save