KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_attribute_mapper.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <algorithm>
23#include <cctype>
24
25
27{
33
34 m_standardMappings["part type"] = FIELD_VALUE;
35 m_standardMappings["part-type"] = FIELD_VALUE;
36 m_standardMappings["parttype"] = FIELD_VALUE;
38 m_standardMappings["part_type"] = FIELD_VALUE;
39
45
47 m_standardMappings["data sheet"] = FIELD_DATASHEET;
49 m_standardMappings["specification"] = FIELD_DATASHEET;
50
51 m_standardMappings["part number"] = FIELD_MPN;
52 m_standardMappings["part_number"] = FIELD_MPN;
53 m_standardMappings["partnumber"] = FIELD_MPN;
56 m_standardMappings["mfr part number"] = FIELD_MPN;
57 m_standardMappings["mfr_part_number"] = FIELD_MPN;
58
59 m_standardMappings["manufacturer"] = FIELD_MANUFACTURER;
63}
64
65
66std::string PADS_ATTRIBUTE_MAPPER::normalizeAttrName( const std::string& aName ) const
67{
68 std::string normalized;
69 normalized.reserve( aName.size() );
70
71 for( char c : aName )
72 {
73 normalized += static_cast<char>( std::tolower( static_cast<unsigned char>( c ) ) );
74 }
75
76 return normalized;
77}
78
79
80std::string PADS_ATTRIBUTE_MAPPER::GetKiCadFieldName( const std::string& aPadsAttr ) const
81{
82 std::string normalized = normalizeAttrName( aPadsAttr );
83
84 // Custom mappings take precedence over the standard ones.
85 auto customIt = m_customMappings.find( normalized );
86
87 if( customIt != m_customMappings.end() )
88 return customIt->second;
89
90 auto standardIt = m_standardMappings.find( normalized );
91
92 if( standardIt != m_standardMappings.end() )
93 return standardIt->second;
94
95 return aPadsAttr;
96}
97
98
99bool PADS_ATTRIBUTE_MAPPER::IsStandardField( const std::string& aPadsAttr ) const
100{
101 return IsReferenceField( aPadsAttr ) || IsValueField( aPadsAttr ) || IsFootprintField( aPadsAttr );
102}
103
104
105bool PADS_ATTRIBUTE_MAPPER::IsReferenceField( const std::string& aPadsAttr ) const
106{
107 std::string fieldName = GetKiCadFieldName( aPadsAttr );
108 return fieldName == FIELD_REFERENCE;
109}
110
111
112bool PADS_ATTRIBUTE_MAPPER::IsValueField( const std::string& aPadsAttr ) const
113{
114 std::string fieldName = GetKiCadFieldName( aPadsAttr );
115 return fieldName == FIELD_VALUE;
116}
117
118
119bool PADS_ATTRIBUTE_MAPPER::IsFootprintField( const std::string& aPadsAttr ) const
120{
121 std::string fieldName = GetKiCadFieldName( aPadsAttr );
122 return fieldName == FIELD_FOOTPRINT;
123}
124
125
126void PADS_ATTRIBUTE_MAPPER::AddMapping( const std::string& aPadsAttr, const std::string& aKiCadField )
127{
128 std::string normalized = normalizeAttrName( aPadsAttr );
129 m_customMappings[normalized] = aKiCadField;
130}
static constexpr const char * FIELD_MANUFACTURER
std::map< std::string, std::string > m_standardMappings
static constexpr const char * FIELD_DATASHEET
std::map< std::string, std::string > m_customMappings
bool IsReferenceField(const std::string &aPadsAttr) const
std::string GetKiCadFieldName(const std::string &aPadsAttr) const
Get the KiCad field name for a PADS attribute, or the original name unchanged when no mapping exists.
bool IsFootprintField(const std::string &aPadsAttr) const
static constexpr const char * FIELD_REFERENCE
static constexpr const char * FIELD_MPN
bool IsStandardField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to a standard KiCad field (Reference, Value, or Footprint).
void AddMapping(const std::string &aPadsAttr, const std::string &aKiCadField)
Add or override a custom attribute mapping.
static constexpr const char * FIELD_VALUE
std::string normalizeAttrName(const std::string &aName) const
bool IsValueField(const std::string &aPadsAttr) const
static constexpr const char * FIELD_FOOTPRINT