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 (C) 2004-2023 KiCad Developers, see change_log.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <bitmaps.h>
25#include <cstddef>
26#include <core/arraydim.h>
27#include <magic_enum.hpp>
28#include <lib_pin.h>
29#include "pgm_base.h"
30
31
32// These are true singletons so it's OK for them to be globals.
33
34static std::vector<BITMAPS> g_typeIcons;
35static wxArrayString g_typeNames;
36
37static std::vector<BITMAPS> g_shapeIcons;
38static wxArrayString g_shapeNames;
39
40static std::vector<BITMAPS> g_orientationIcons;
41static wxArrayString g_orientationNames;
42
43
45{
46 wxString name;
48};
49
50
51std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> g_pinTypes = {
54 { ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), BITMAPS::pintype_bidi } },
64};
65
66
67int g_pinTypesLanguage = wxLANGUAGE_UNKNOWN;
68
69
71{
72 wxString name;
74};
75
76
77// clang-format off
78const std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> pinShapes = {
88};
89// clang-format on
90
91
92// bitmaps to show pins orientations in dialog editor
93// must have same order than pin_orientation_names
95{
100};
101
102
103// clang-format off
104std::map<PIN_ORIENTATION, struct pinShapeStruct> pinOrientations = {
109};
110// clang-format on
111
112
114{
115 wxASSERT( index < magic_enum::enum_count<PIN_ORIENTATION>() );
116 return magic_enum::enum_value<PIN_ORIENTATION>( index );
117}
118
119
121{
122 auto index = magic_enum::enum_index<PIN_ORIENTATION>( code );
123
124 if( index.has_value() )
125 return index.value();
126
127 return wxNOT_FOUND;
128}
129
130
132{
133 for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
134 {
135 g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
136 g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
137 }
138
139 for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
140 {
141 g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
142 g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
143 }
144
145 for( PIN_ORIENTATION orientation : magic_enum::enum_values<PIN_ORIENTATION>() )
146 {
147 g_orientationIcons.push_back( PinOrientationGetBitmap( orientation ) );
148 g_orientationNames.push_back( PinOrientationName( orientation ) );
149 }
150}
151
152
153const wxArrayString& PinTypeNames()
154{
155 if( g_typeNames.empty() )
156 InitTables();
157
158 return g_typeNames;
159}
160
161
162const std::vector<BITMAPS>& PinTypeIcons()
163{
164 if( g_typeIcons.empty() )
165 InitTables();
166
167 return g_typeIcons;
168}
169
170
171const wxArrayString& PinShapeNames()
172{
173 if( g_shapeNames.empty() )
174 InitTables();
175
176 return g_shapeNames;
177}
178
179
180const std::vector<BITMAPS>& PinShapeIcons()
181{
182 if( g_shapeIcons.empty() )
183 InitTables();
184
185 return g_shapeIcons;
186}
187
188
189const wxArrayString& PinOrientationNames()
190{
191 if( g_orientationNames.empty() )
192 InitTables();
193
194 return g_orientationNames;
195}
196
197
198const std::vector<BITMAPS>& PinOrientationIcons()
199{
200 if( g_orientationIcons.empty() )
201 InitTables();
202
203 return g_orientationIcons;
204}
205
206
208{
209 if( g_pinTypesLanguage != Pgm().GetSelectedLanguageIdentifier() )
210 {
211 g_pinTypes[ELECTRICAL_PINTYPE::PT_INPUT].name = _( "Input" );
212 g_pinTypes[ELECTRICAL_PINTYPE::PT_OUTPUT].name = _( "Output" );
213 g_pinTypes[ELECTRICAL_PINTYPE::PT_BIDI].name = _( "Bidirectional" );
214 g_pinTypes[ELECTRICAL_PINTYPE::PT_TRISTATE].name = _( "Tri-state" );
215 g_pinTypes[ELECTRICAL_PINTYPE::PT_PASSIVE].name = _( "Passive" );
216 g_pinTypes[ELECTRICAL_PINTYPE::PT_NIC].name = _( "Free" );
217 g_pinTypes[ELECTRICAL_PINTYPE::PT_UNSPECIFIED].name = _( "Unspecified" );
218 g_pinTypes[ELECTRICAL_PINTYPE::PT_POWER_IN].name = _( "Power input" );
219 g_pinTypes[ELECTRICAL_PINTYPE::PT_POWER_OUT].name = _( "Power output" );
220 g_pinTypes[ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR].name = _( "Open collector" );
221 g_pinTypes[ELECTRICAL_PINTYPE::PT_OPENEMITTER].name = _( "Open emitter" );
222 g_pinTypes[ELECTRICAL_PINTYPE::PT_NC].name = _( "Unconnected" );
223
224 g_pinTypesLanguage = Pgm().GetSelectedLanguageIdentifier();
225 }
226
227 auto findIt = g_pinTypes.find( aType );
228
229 wxCHECK_MSG( findIt != g_pinTypes.end(), wxT( "???" ), wxT( "Pin type not found!" ) );
230
231 return findIt->second.name;
232}
233
234
236{
237 auto findIt = g_pinTypes.find( aType );
238
239 wxCHECK_MSG( findIt != g_pinTypes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
240
241 return findIt->second.bitmap;
242}
243
244
246{
247 auto findIt = pinShapes.find( aShape );
248
249 wxCHECK_MSG( findIt != pinShapes.end(), wxT( "?" ), wxT( "Pin type not found!" ) );
250
251 return findIt->second.name;
252}
253
254
256{
257 auto findIt = pinShapes.find( aShape );
258
259 wxCHECK_MSG( findIt != pinShapes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
260
261 return findIt->second.bitmap;
262}
263
264
265wxString PinOrientationName( PIN_ORIENTATION aOrientation )
266{
267 auto findIt = pinOrientations.find( aOrientation );
268
269 wxCHECK_MSG( findIt != pinOrientations.end(), wxT( "?" ), wxT( "Pin orientation not found!" ) );
270
271 return findIt->second.name;
272}
273
274
276{
277 auto findIt = pinOrientations.find( aOrientation );
278
279 wxCHECK_MSG( findIt != pinOrientations.end(), BITMAPS::INVALID_BITMAP,
280 wxT( "Pin orientation not found!" ) );
281
282 return findIt->second.bitmap;
283}
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
@ pinorient_up
@ pintype_notspecif
@ pinshape_invert
@ pintype_bidi
@ pinshape_clock_active_low
@ pinorient_right
@ pinshape_clock_normal
@ pinorient_down
@ pintype_passive
@ pinshape_nonlogic
@ pinshape_clock_invert
@ pintype_output
@ INVALID_BITMAP
@ pinshape_active_low_input
@ pintype_opencoll
@ pinshape_normal
@ pintype_powerinput
@ pinshape_active_low_output
@ pinorient_left
@ pintype_noconnect
@ pintype_poweroutput
@ pintype_input
@ pintype_3states
@ pintype_openemit
@ pinshape_clock_fall
#define _(s)
see class PGM_BASE
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:162
std::map< PIN_ORIENTATION, struct pinShapeStruct > pinOrientations
Definition: pin_type.cpp:104
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:255
static const BITMAPS iconsPinsOrientations[]
Definition: pin_type.cpp:94
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:153
static std::vector< BITMAPS > g_orientationIcons
Definition: pin_type.cpp:40
static std::vector< BITMAPS > g_typeIcons
Definition: pin_type.cpp:34
int PinOrientationIndex(PIN_ORIENTATION code)
Definition: pin_type.cpp:120
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:207
int g_pinTypesLanguage
Definition: pin_type.cpp:67
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:171
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:180
std::map< ELECTRICAL_PINTYPE, struct pinTypeStruct > g_pinTypes
Definition: pin_type.cpp:51
static wxArrayString g_shapeNames
Definition: pin_type.cpp:38
static wxArrayString g_typeNames
Definition: pin_type.cpp:35
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:235
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:245
const wxArrayString & PinOrientationNames()
Definition: pin_type.cpp:189
const std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > pinShapes
Definition: pin_type.cpp:78
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:265
static std::vector< BITMAPS > g_shapeIcons
Definition: pin_type.cpp:37
static wxArrayString g_orientationNames
Definition: pin_type.cpp:41
BITMAPS PinOrientationGetBitmap(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:275
void InitTables()
Definition: pin_type.cpp:131
PIN_ORIENTATION PinOrientationCode(size_t index)
Definition: pin_type.cpp:113
const std::vector< BITMAPS > & PinOrientationIcons()
Definition: pin_type.cpp:198
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
@ PT_INPUT
usual pin input: must be connected
@ PT_NC
not connected (must be left open)
@ PT_OUTPUT
usual output
@ PT_TRISTATE
tris state bus pin
@ PT_NIC
not internally connected (may be connected to anything)
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_OPENEMITTER
pin type open emitter
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
@ PT_OPENCOLLECTOR
pin type open collector
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:53
#define GRAPHIC_PINSHAPES_TOTAL
Definition: pin_type.h:70
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:75
GRAPHIC_PINSHAPE
Definition: pin_type.h:56
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
wxString name
Definition: pin_type.cpp:72
BITMAPS bitmap
Definition: pin_type.cpp:73
wxString name
Definition: pin_type.cpp:46
BITMAPS bitmap
Definition: pin_type.cpp:47