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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <algorithm>
23#include <cctype>
24
25
27{
28 // Standard PADS attribute mappings to KiCad fields
29 // Reference designator variations
35
36 // Value/Part type variations
37 m_standardMappings["part type"] = FIELD_VALUE;
38 m_standardMappings["part-type"] = FIELD_VALUE;
39 m_standardMappings["parttype"] = FIELD_VALUE;
41 m_standardMappings["part_type"] = FIELD_VALUE;
42
43 // Footprint/Decal variations
49
50 // Datasheet variations
52 m_standardMappings["data sheet"] = FIELD_DATASHEET;
54 m_standardMappings["specification"] = FIELD_DATASHEET;
55
56 // MPN (Manufacturer Part Number) variations
57 m_standardMappings["part number"] = FIELD_MPN;
58 m_standardMappings["part_number"] = FIELD_MPN;
59 m_standardMappings["partnumber"] = FIELD_MPN;
62 m_standardMappings["mfr part number"] = FIELD_MPN;
63 m_standardMappings["mfr_part_number"] = FIELD_MPN;
64
65 // Manufacturer variations
66 m_standardMappings["manufacturer"] = FIELD_MANUFACTURER;
70}
71
72
73std::string PADS_ATTRIBUTE_MAPPER::normalizeAttrName( const std::string& aName ) const
74{
75 std::string normalized;
76 normalized.reserve( aName.size() );
77
78 for( char c : aName )
79 {
80 normalized += static_cast<char>( std::tolower( static_cast<unsigned char>( c ) ) );
81 }
82
83 return normalized;
84}
85
86
87std::string PADS_ATTRIBUTE_MAPPER::GetKiCadFieldName( const std::string& aPadsAttr ) const
88{
89 std::string normalized = normalizeAttrName( aPadsAttr );
90
91 // Check custom mappings first (they take precedence)
92 auto customIt = m_customMappings.find( normalized );
93
94 if( customIt != m_customMappings.end() )
95 return customIt->second;
96
97 // Then check standard mappings
98 auto standardIt = m_standardMappings.find( normalized );
99
100 if( standardIt != m_standardMappings.end() )
101 return standardIt->second;
102
103 // Return original name if no mapping exists
104 return aPadsAttr;
105}
106
107
108bool PADS_ATTRIBUTE_MAPPER::IsStandardField( const std::string& aPadsAttr ) const
109{
110 return IsReferenceField( aPadsAttr ) || IsValueField( aPadsAttr ) || IsFootprintField( aPadsAttr );
111}
112
113
114bool PADS_ATTRIBUTE_MAPPER::IsReferenceField( const std::string& aPadsAttr ) const
115{
116 std::string fieldName = GetKiCadFieldName( aPadsAttr );
117 return fieldName == FIELD_REFERENCE;
118}
119
120
121bool PADS_ATTRIBUTE_MAPPER::IsValueField( const std::string& aPadsAttr ) const
122{
123 std::string fieldName = GetKiCadFieldName( aPadsAttr );
124 return fieldName == FIELD_VALUE;
125}
126
127
128bool PADS_ATTRIBUTE_MAPPER::IsFootprintField( const std::string& aPadsAttr ) const
129{
130 std::string fieldName = GetKiCadFieldName( aPadsAttr );
131 return fieldName == FIELD_FOOTPRINT;
132}
133
134
135void PADS_ATTRIBUTE_MAPPER::AddMapping( const std::string& aPadsAttr, const std::string& aKiCadField )
136{
137 std::string normalized = normalizeAttrName( aPadsAttr );
138 m_customMappings[normalized] = aKiCadField;
139}
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
Check if a PADS attribute maps to the Reference field.
std::string GetKiCadFieldName(const std::string &aPadsAttr) const
Get the KiCad field name for a PADS attribute.
bool IsFootprintField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to the Footprint field.
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.
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
Check if a PADS attribute maps to the Value field.
static constexpr const char * FIELD_FOOTPRINT