KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pin_map.h
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
20#pragma once
21
22#include <kicommon.h>
23#include <lib_id.h>
24
25#include <nlohmann/json_fwd.hpp>
26
27#include <unordered_map>
28#include <vector>
29#include <wx/string.h>
30#include <wx/arrstr.h> // gives std::vector<wxString> dllimport attribution on MSVC
31
32
42{
43 wxString m_PinNumber;
44 wxString m_PadNumber;
45
46 bool operator==( const PIN_MAP_ENTRY& aOther ) const
47 {
48 return m_PinNumber == aOther.m_PinNumber && m_PadNumber == aOther.m_PadNumber;
49 }
50};
51
52
65{
66public:
67 PIN_MAP() = default;
68 explicit PIN_MAP( const wxString& aName );
69
70 const wxString& GetName() const { return m_name; }
71 void SetName( const wxString& aName ) { m_name = aName; }
72
77 void SetEntry( const wxString& aPinNumber, const wxString& aPadNumber );
78
82 void ClearEntry( const wxString& aPinNumber );
83
84 bool HasEntry( const wxString& aPinNumber ) const;
85
90 const wxString& GetPadNumber( const wxString& aPinNumber ) const;
91
92 const std::vector<PIN_MAP_ENTRY>& GetEntries() const { return m_entries; }
93
94 bool IsEmpty() const { return m_entries.empty(); }
95
103 bool IsIdentity( const std::vector<wxString>& aPinNumbers ) const;
104
105 bool operator==( const PIN_MAP& aOther ) const;
106
107private:
108 std::vector<PIN_MAP_ENTRY>::iterator findEntry( const wxString& aPinNumber );
109 std::vector<PIN_MAP_ENTRY>::const_iterator findEntry( const wxString& aPinNumber ) const;
110
111 wxString m_name;
112 std::vector<PIN_MAP_ENTRY> m_entries;
113};
114
115
124{
125public:
129 void AddOrReplace( PIN_MAP aMap );
130
134 void Remove( const wxString& aName );
135
136 const PIN_MAP* FindByName( const wxString& aName ) const;
137 PIN_MAP* FindByName( const wxString& aName );
138
139 const std::vector<PIN_MAP>& GetAll() const { return m_maps; }
140 bool IsEmpty() const { return m_maps.empty(); }
141
142 bool operator==( const PIN_MAP_SET& aOther ) const { return m_maps == aOther.m_maps; }
143 bool operator!=( const PIN_MAP_SET& aOther ) const { return !( *this == aOther ); }
144
145private:
146 std::vector<PIN_MAP> m_maps; // ordered for stable file output
147};
148
149
159{
161 wxString m_MapName;
162
163 bool operator==( const ASSOCIATED_FOOTPRINT& aOther ) const
164 {
165 return m_FootprintLibId == aOther.m_FootprintLibId && m_MapName == aOther.m_MapName;
166 }
167};
168
169
184
185
200{
203 std::vector<PIN_MAP_ENTRY> m_Edits;
204
210 bool IsDefault() const
211 {
213 }
214
220
221 bool operator==( const PIN_MAP_INSTANCE_OVERRIDE& aOther ) const
222 {
223 return m_Mode == aOther.m_Mode && m_ActiveMapName == aOther.m_ActiveMapName
224 && m_Edits == aOther.m_Edits;
225 }
226
227 bool operator!=( const PIN_MAP_INSTANCE_OVERRIDE& aOther ) const { return !( *this == aOther ); }
228};
229
230
239 const wxString& aName,
240 const std::unordered_map<wxString, std::vector<wxString>>& aAssignments );
241
242
250KICOMMON_API std::unordered_map<wxString, std::vector<wxString>>
251ParseLegacyPinAssignments( const nlohmann::json& aArray );
252
259KICOMMON_API PIN_MAP_SET ParsePinMapSet( const nlohmann::json& aParent );
260
267KICOMMON_API std::vector<ASSOCIATED_FOOTPRINT>
268ParseAssociatedFootprints( const nlohmann::json& aParent );
bool operator==(const wxAuiPaneInfo &aLhs, const wxAuiPaneInfo &aRhs)
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
A symbol-owned ordered set of named pin maps.
Definition pin_map.h:124
bool IsEmpty() const
Definition pin_map.h:140
const std::vector< PIN_MAP > & GetAll() const
Definition pin_map.h:139
void AddOrReplace(PIN_MAP aMap)
Insert aMap, replacing any existing entry with the same name.
Definition pin_map.cpp:113
void Remove(const wxString &aName)
Remove the map with the given name.
Definition pin_map.cpp:122
bool operator!=(const PIN_MAP_SET &aOther) const
Definition pin_map.h:143
const PIN_MAP * FindByName(const wxString &aName) const
Definition pin_map.cpp:133
bool operator==(const PIN_MAP_SET &aOther) const
Definition pin_map.h:142
std::vector< PIN_MAP > m_maps
Definition pin_map.h:146
A named pin map.
Definition pin_map.h:65
PIN_MAP()=default
void SetName(const wxString &aName)
Definition pin_map.h:71
const std::vector< PIN_MAP_ENTRY > & GetEntries() const
Definition pin_map.h:92
const wxString & GetName() const
Definition pin_map.h:70
bool IsEmpty() const
Definition pin_map.h:94
wxString m_name
Definition pin_map.h:111
std::vector< PIN_MAP_ENTRY > m_entries
Definition pin_map.h:112
#define KICOMMON_API
Definition kicommon.h:27
KICOMMON_API PIN_MAP_SET ParsePinMapSet(const nlohmann::json &aParent)
Parse the spec-form named maps from aParent["pin_maps"] into a PIN_MAP_SET (issue #2282).
Definition pin_map.cpp:221
KICOMMON_API std::unordered_map< wxString, std::vector< wxString > > ParseLegacyPinAssignments(const nlohmann::json &aArray)
Parse the legacy flat pin-assignment JSON array (MR !2540 form) into a symbol-pin to footprint-pad(s)...
Definition pin_map.cpp:187
PIN_MAP_OVERRIDE_MODE
Override mode stored on a SCH_SYMBOL_INSTANCE.
Definition pin_map.h:178
KICOMMON_API std::vector< ASSOCIATED_FOOTPRINT > ParseAssociatedFootprints(const nlohmann::json &aParent)
Parse the spec-form footprint associations from aParent["associated_footprints"] (issue #2282).
Definition pin_map.cpp:254
KICOMMON_API PIN_MAP MakeLegacyPinMap(const wxString &aName, const std::unordered_map< wxString, std::vector< wxString > > &aAssignments)
Build a single named PIN_MAP from a legacy symbol-pin to footprint-pad(s) assignment table (the flat ...
Definition pin_map.cpp:151
A first-class footprint choice on a LIB_SYMBOL, tied to a named pin map.
Definition pin_map.h:159
bool operator==(const ASSOCIATED_FOOTPRINT &aOther) const
Definition pin_map.h:163
LIB_ID m_FootprintLibId
Definition pin_map.h:160
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Definition pin_map.h:42
bool operator==(const PIN_MAP_ENTRY &aOther) const
Definition pin_map.h:46
wxString m_PadNumber
Definition pin_map.h:44
wxString m_PinNumber
Definition pin_map.h:43
Per-instance override of the active pin map and a sparse delta on top.
Definition pin_map.h:200
bool operator==(const PIN_MAP_INSTANCE_OVERRIDE &aOther) const
Definition pin_map.h:221
std::vector< PIN_MAP_ENTRY > m_Edits
Definition pin_map.h:203
bool operator!=(const PIN_MAP_INSTANCE_OVERRIDE &aOther) const
Definition pin_map.h:227
bool IsDefault() const
Definition pin_map.h:210
PIN_MAP_OVERRIDE_MODE m_Mode
Definition pin_map.h:201
bool IsDelegate() const
Definition pin_map.h:219