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// These are true singletons so it's OK for them to be globals.
28
29static std::vector<BITMAPS> g_typeIcons;
30static wxArrayString g_typeNames;
31
32static std::vector<BITMAPS> g_shapeIcons;
33static wxArrayString g_shapeNames;
34
35static std::vector<BITMAPS> g_orientationIcons;
36static wxArrayString g_orientationNames;
37
38
40{
41 wxString name;
43};
44
46{
47 wxString name;
49};
50
51static std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> g_pinElectricalTypes;
52static std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> g_pinShapes;
53static std::map<PIN_ORIENTATION, struct pinShapeStruct> g_pinOrientations;
54
55
56static int g_language = wxLANGUAGE_UNKNOWN;
57
58
60{
61 wxASSERT( index < magic_enum::enum_count<PIN_ORIENTATION>() );
62 return magic_enum::enum_value<PIN_ORIENTATION>( index );
63}
64
65
67{
68 auto index = magic_enum::enum_index<PIN_ORIENTATION>( code );
69
70 if( index.has_value() )
71 return index.value();
72
73 return wxNOT_FOUND;
74}
75
76
78{
79 // clang-format off
83 { ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), BITMAPS::pintype_bidi } },
94 };
95
96 g_pinShapes = {
106 { GRAPHIC_PINSHAPE::INHERIT, { _( "Unspecified" ), BITMAPS::pintype_notspecif } },
107 };
108
114 { PIN_ORIENTATION::INHERIT, { _( "Unspecified" ), BITMAPS::pintype_notspecif } },
115 };
116 // clang-format on
117
119
120 g_typeIcons.clear();
121 g_typeNames.clear();
122
123 for( const auto& [pinType, pinData] : g_pinElectricalTypes )
124 {
125 g_typeIcons.push_back( pinData.bitmap );
126 g_typeNames.push_back( pinData.name );
127 }
128
129 g_shapeIcons.clear();
130 g_shapeNames.clear();
131
132 for( const auto& [shapeType, shapeData] : g_pinShapes )
133 {
134 g_shapeIcons.push_back( shapeData.bitmap );
135 g_shapeNames.push_back( shapeData.name );
136 }
137
138 g_orientationIcons.clear();
139 g_orientationNames.clear();
140
141 for( const auto& [orientationType, orientationData] : g_pinOrientations )
142 {
143 g_orientationIcons.push_back( orientationData.bitmap );
144 g_orientationNames.push_back( orientationData.name );
145 }
146}
147
148
149const wxArrayString& PinTypeNames()
150{
151 if( g_typeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
152 InitTables();
153
154 return g_typeNames;
155}
156
157
158const std::vector<BITMAPS>& PinTypeIcons()
159{
160 if( g_typeIcons.empty() )
161 InitTables();
162
163 return g_typeIcons;
164}
165
166
167const wxArrayString& PinShapeNames()
168{
169 if( g_shapeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
170 InitTables();
171
172 return g_shapeNames;
173}
174
175
176const std::vector<BITMAPS>& PinShapeIcons()
177{
178 if( g_shapeIcons.empty() )
179 InitTables();
180
181 return g_shapeIcons;
182}
183
184
185const wxArrayString& PinOrientationNames()
186{
187 if( g_orientationNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
188 InitTables();
189
190 return g_orientationNames;
191}
192
193
194const std::vector<BITMAPS>& PinOrientationIcons()
195{
196 if( g_orientationIcons.empty() )
197 InitTables();
198
199 return g_orientationIcons;
200}
201
202
204{
205 if( g_pinElectricalTypes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
206 InitTables();
207
208 auto it = g_pinElectricalTypes.find( aType );
209
210 wxCHECK_MSG( it != g_pinElectricalTypes.end(), wxT( "???" ),
211 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
212
213 return it->second.name;
214}
215
216
218{
219 if( g_pinElectricalTypes.empty() )
220 InitTables();
221
222 auto it = g_pinElectricalTypes.find( aType );
223
224 wxCHECK_MSG( it != g_pinElectricalTypes.end(), BITMAPS::INVALID_BITMAP,
225 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
226
227 return it->second.bitmap;
228}
229
230
232{
233 if( g_pinShapes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
234 InitTables();
235
236 auto it = g_pinShapes.find( aShape );
237
238 wxCHECK_MSG( it != g_pinShapes.end(), wxT( "?" ),
239 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
240
241 return it->second.name;
242}
243
244
246{
247 if( g_pinShapes.empty() )
248 InitTables();
249
250 auto it = g_pinShapes.find( aShape );
251
252 wxCHECK_MSG( it != g_pinShapes.end(), BITMAPS::INVALID_BITMAP,
253 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
254
255 return it->second.bitmap;
256}
257
258
259wxString PinOrientationName( PIN_ORIENTATION aOrientation )
260{
261 if( g_pinOrientations.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
262 InitTables();
263
264 auto it = g_pinOrientations.find( aOrientation );
265
266 wxCHECK_MSG( it != g_pinOrientations.end(), wxT( "?" ),
267 wxString::Format( "Pin orientation not found for type %d!", (int) aOrientation ) );
268
269 return it->second.name;
270}
271
272
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:230
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
const std::vector< BITMAPS > & PinTypeIcons()
Definition pin_type.cpp:158
static std::map< PIN_ORIENTATION, struct pinShapeStruct > g_pinOrientations
Definition pin_type.cpp:53
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition pin_type.cpp:245
static int g_language
Definition pin_type.cpp:56
static std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > g_pinShapes
Definition pin_type.cpp:52
const wxArrayString & PinTypeNames()
Definition pin_type.cpp:149
static std::vector< BITMAPS > g_orientationIcons
Definition pin_type.cpp:35
static std::vector< BITMAPS > g_typeIcons
Definition pin_type.cpp:29
int PinOrientationIndex(PIN_ORIENTATION code)
Definition pin_type.cpp:66
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition pin_type.cpp:203
const wxArrayString & PinShapeNames()
Definition pin_type.cpp:167
const std::vector< BITMAPS > & PinShapeIcons()
Definition pin_type.cpp:176
static wxArrayString g_shapeNames
Definition pin_type.cpp:33
static wxArrayString g_typeNames
Definition pin_type.cpp:30
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition pin_type.cpp:217
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition pin_type.cpp:231
const wxArrayString & PinOrientationNames()
Definition pin_type.cpp:185
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition pin_type.cpp:259
static std::vector< BITMAPS > g_shapeIcons
Definition pin_type.cpp:32
static wxArrayString g_orientationNames
Definition pin_type.cpp:36
static std::map< ELECTRICAL_PINTYPE, struct pinTypeStruct > g_pinElectricalTypes
Definition pin_type.cpp:51
void InitTables()
Definition pin_type.cpp:77
PIN_ORIENTATION PinOrientationCode(size_t index)
Definition pin_type.cpp:59
const std::vector< BITMAPS > & PinOrientationIcons()
Definition pin_type.cpp:194
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:47
BITMAPS bitmap
Definition pin_type.cpp:48
wxString name
Definition pin_type.cpp:41
BITMAPS bitmap
Definition pin_type.cpp:42