KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pin_type.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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
20#include <bitmaps.h>
21#include <cstddef>
22#include <magic_enum.hpp>
23#include <sch_pin.h>
24#include "pgm_base.h"
25
26
27// Library loading initializes and reads these caches on worker threads. Keep them local to
28// each thread so initialization and language changes cannot invalidate another thread's data.
29
30static thread_local std::vector<BITMAPS> g_typeIcons;
31static thread_local wxArrayString g_typeNames;
32
33static thread_local std::vector<BITMAPS> g_shapeIcons;
34static thread_local wxArrayString g_shapeNames;
35
36static thread_local std::vector<BITMAPS> g_orientationIcons;
37static thread_local wxArrayString g_orientationNames;
38
39
41{
42 wxString name;
44};
45
47{
48 wxString name;
50};
51
52static thread_local std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> g_pinElectricalTypes;
53static thread_local std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> g_pinShapes;
54static thread_local std::map<PIN_ORIENTATION, struct pinShapeStruct> g_pinOrientations;
55
56
57static thread_local int g_language = wxLANGUAGE_UNKNOWN;
58
59
61{
62 wxASSERT( index < magic_enum::enum_count<PIN_ORIENTATION>() );
63 return magic_enum::enum_value<PIN_ORIENTATION>( index );
64}
65
66
68{
69 auto index = magic_enum::enum_index<PIN_ORIENTATION>( code );
70
71 if( index.has_value() )
72 return index.value();
73
74 return wxNOT_FOUND;
75}
76
77
79{
80 // clang-format off
84 { ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), BITMAPS::pintype_bidi } },
95 };
96
97 g_pinShapes = {
107 { GRAPHIC_PINSHAPE::INHERIT, { _( "Unspecified" ), BITMAPS::pintype_notspecif } },
108 };
109
115 { PIN_ORIENTATION::INHERIT, { _( "Unspecified" ), BITMAPS::pintype_notspecif } },
116 };
117 // clang-format on
118
120
121 g_typeIcons.clear();
122 g_typeNames.clear();
123
124 for( const auto& [pinType, pinData] : g_pinElectricalTypes )
125 {
126 g_typeIcons.push_back( pinData.bitmap );
127 g_typeNames.push_back( pinData.name );
128 }
129
130 g_shapeIcons.clear();
131 g_shapeNames.clear();
132
133 for( const auto& [shapeType, shapeData] : g_pinShapes )
134 {
135 g_shapeIcons.push_back( shapeData.bitmap );
136 g_shapeNames.push_back( shapeData.name );
137 }
138
139 g_orientationIcons.clear();
140 g_orientationNames.clear();
141
142 for( const auto& [orientationType, orientationData] : g_pinOrientations )
143 {
144 g_orientationIcons.push_back( orientationData.bitmap );
145 g_orientationNames.push_back( orientationData.name );
146 }
147}
148
149
150const wxArrayString& PinTypeNames()
151{
152 if( g_typeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
153 InitTables();
154
155 return g_typeNames;
156}
157
158
159const std::vector<BITMAPS>& PinTypeIcons()
160{
161 if( g_typeIcons.empty() )
162 InitTables();
163
164 return g_typeIcons;
165}
166
167
168const wxArrayString& PinShapeNames()
169{
170 if( g_shapeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
171 InitTables();
172
173 return g_shapeNames;
174}
175
176
177const std::vector<BITMAPS>& PinShapeIcons()
178{
179 if( g_shapeIcons.empty() )
180 InitTables();
181
182 return g_shapeIcons;
183}
184
185
186const wxArrayString& PinOrientationNames()
187{
188 if( g_orientationNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
189 InitTables();
190
191 return g_orientationNames;
192}
193
194
195const std::vector<BITMAPS>& PinOrientationIcons()
196{
197 if( g_orientationIcons.empty() )
198 InitTables();
199
200 return g_orientationIcons;
201}
202
203
205{
206 if( g_pinElectricalTypes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
207 InitTables();
208
209 auto it = g_pinElectricalTypes.find( aType );
210
211 wxCHECK_MSG( it != g_pinElectricalTypes.end(), wxT( "???" ),
212 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
213
214 return it->second.name;
215}
216
217
219{
220 if( g_pinElectricalTypes.empty() )
221 InitTables();
222
223 auto it = g_pinElectricalTypes.find( aType );
224
225 wxCHECK_MSG( it != g_pinElectricalTypes.end(), BITMAPS::INVALID_BITMAP,
226 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
227
228 return it->second.bitmap;
229}
230
231
233{
234 if( g_pinShapes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
235 InitTables();
236
237 auto it = g_pinShapes.find( aShape );
238
239 wxCHECK_MSG( it != g_pinShapes.end(), wxT( "?" ),
240 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
241
242 return it->second.name;
243}
244
245
247{
248 if( g_pinShapes.empty() )
249 InitTables();
250
251 auto it = g_pinShapes.find( aShape );
252
253 wxCHECK_MSG( it != g_pinShapes.end(), BITMAPS::INVALID_BITMAP,
254 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
255
256 return it->second.bitmap;
257}
258
259
260wxString PinOrientationName( PIN_ORIENTATION aOrientation )
261{
262 if( g_pinOrientations.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
263 InitTables();
264
265 auto it = g_pinOrientations.find( aOrientation );
266
267 wxCHECK_MSG( it != g_pinOrientations.end(), wxT( "?" ),
268 wxString::Format( "Pin orientation not found for type %d!", (int) aOrientation ) );
269
270 return it->second.name;
271}
272
273
int index
BITMAPS
A list of all bitmap identifiers.
@ pintype_notspecif
@ pinshape_invert
@ pinshape_clock_active_low
@ pinorient_right
@ pinshape_clock_normal
@ pintype_passive
@ pinshape_nonlogic
@ pinshape_clock_invert
@ INVALID_BITMAP
@ pinshape_active_low_input
@ pintype_opencoll
@ pinshape_normal
@ pintype_powerinput
@ pinshape_active_low_output
@ pintype_noconnect
@ pintype_poweroutput
@ pintype_3states
@ pintype_openemit
@ pinshape_clock_fall
virtual int GetSelectedLanguageIdentifier() const
Definition pgm_base.h:229
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
const std::vector< BITMAPS > & PinTypeIcons()
Definition pin_type.cpp:159
static thread_local std::vector< BITMAPS > g_typeIcons
Definition pin_type.cpp:30
static thread_local std::map< ELECTRICAL_PINTYPE, struct pinTypeStruct > g_pinElectricalTypes
Definition pin_type.cpp:52
static thread_local std::map< PIN_ORIENTATION, struct pinShapeStruct > g_pinOrientations
Definition pin_type.cpp:54
static thread_local int g_language
Definition pin_type.cpp:57
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition pin_type.cpp:246
static thread_local wxArrayString g_shapeNames
Definition pin_type.cpp:34
static thread_local wxArrayString g_orientationNames
Definition pin_type.cpp:37
static thread_local wxArrayString g_typeNames
Definition pin_type.cpp:31
const wxArrayString & PinTypeNames()
Definition pin_type.cpp:150
int PinOrientationIndex(PIN_ORIENTATION code)
Definition pin_type.cpp:67
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition pin_type.cpp:204
const wxArrayString & PinShapeNames()
Definition pin_type.cpp:168
const std::vector< BITMAPS > & PinShapeIcons()
Definition pin_type.cpp:177
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition pin_type.cpp:218
static thread_local std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > g_pinShapes
Definition pin_type.cpp:53
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition pin_type.cpp:232
const wxArrayString & PinOrientationNames()
Definition pin_type.cpp:186
static thread_local std::vector< BITMAPS > g_orientationIcons
Definition pin_type.cpp:36
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition pin_type.cpp:260
static thread_local std::vector< BITMAPS > g_shapeIcons
Definition pin_type.cpp:33
void InitTables()
Definition pin_type.cpp:78
PIN_ORIENTATION PinOrientationCode(size_t index)
Definition pin_type.cpp:60
const std::vector< BITMAPS > & PinOrientationIcons()
Definition pin_type.cpp:195
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition pin_type.h:32
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_NC
not connected (must be left open)
Definition pin_type.h:46
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_TRISTATE
tri state bus pin
Definition pin_type.h:36
@ PT_NIC
not internally connected (may be connected to anything)
Definition pin_type.h:40
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PT_OPENEMITTER
pin type open emitter
Definition pin_type.h:45
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
Definition pin_type.h:43
@ PT_OPENCOLLECTOR
pin type open collector
Definition pin_type.h:44
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:101
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
Definition pin_type.h:123
@ PIN_RIGHT
The pin extends rightwards from the connection point.
Definition pin_type.h:107
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
Definition pin_type.h:114
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition pin_type.h:131
GRAPHIC_PINSHAPE
Definition pin_type.h:80
wxString name
Definition pin_type.cpp:48
BITMAPS bitmap
Definition pin_type.cpp:49
wxString name
Definition pin_type.cpp:42
BITMAPS bitmap
Definition pin_type.cpp:43