KiCad PCB EDA Suite
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-2022 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 <lib_pin.h>
28#include <pin_type.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
92static const int pin_orientation_codes[] =
93{
96 PIN_UP,
98};
99
100
101// bitmaps to show pins orientations in dialog editor
102// must have same order than pin_orientation_names
104{
109};
110
111
112#define PIN_ORIENTATION_CNT arrayDim( pin_orientation_codes )
113
114
115// Helper functions to get the pin orientation name from pin_orientation_codes
116// Note: the strings are *not* static because they are translated and must be built
117// on the fly, to be properly translated
118
119wxString PinOrientationName( unsigned aPinOrientationCode )
120{
121 /* Note: The following name lists are sentence capitalized per the GNOME UI
122 * standards for list controls. Please do not change the capitalization
123 * of these strings unless the GNOME UI standards are changed.
124 */
125 const wxString pin_orientation_names[] =
126 {
127 _( "Right" ),
128 _( "Left" ),
129 _( "Up" ),
130 _( "Down" ),
131 wxT( "???" )
132 };
133
134 if( aPinOrientationCode > PIN_ORIENTATION_CNT )
135 aPinOrientationCode = PIN_ORIENTATION_CNT;
136
137 return pin_orientation_names[ aPinOrientationCode ];
138}
139
140
141int PinOrientationCode( int index )
142{
143 if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
144 return pin_orientation_codes[ index ];
145
146 return PIN_RIGHT;
147}
148
149
150int PinOrientationIndex( int code )
151{
152 size_t i;
153
154 for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
155 {
156 if( pin_orientation_codes[i] == code )
157 return (int) i;
158 }
159
160 return wxNOT_FOUND;
161}
162
163
165{
166 for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
167 {
168 g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
169 g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
170 }
171
172 for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
173 {
174 g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
175 g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
176 }
177
178 for( unsigned i = 0; i < PIN_ORIENTATION_CNT; ++i )
179 {
181 g_orientationNames.push_back( PinOrientationName( i ) );
182 }
183}
184
185
186const wxArrayString& PinTypeNames()
187{
188 if( g_typeNames.empty() )
189 InitTables();
190
191 return g_typeNames;
192}
193
194
195const std::vector<BITMAPS>& PinTypeIcons()
196{
197 if( g_typeIcons.empty() )
198 InitTables();
199
200 return g_typeIcons;
201}
202
203
204const wxArrayString& PinShapeNames()
205{
206 if( g_shapeNames.empty() )
207 InitTables();
208
209 return g_shapeNames;
210}
211
212
213const std::vector<BITMAPS>& PinShapeIcons()
214{
215 if( g_shapeIcons.empty() )
216 InitTables();
217
218 return g_shapeIcons;
219}
220
221
222const wxArrayString& PinOrientationNames()
223{
224 if( g_orientationNames.empty() )
225 InitTables();
226
227 return g_orientationNames;
228}
229
230
231const std::vector<BITMAPS>& PinOrientationIcons()
232{
233 if( g_orientationIcons.empty() )
234 InitTables();
235
236 return g_orientationIcons;
237}
238
239
241{
242 if( g_pinTypesLanguage != Pgm().GetSelectedLanguageIdentifier() )
243 {
244 g_pinTypes[ELECTRICAL_PINTYPE::PT_INPUT].name = _( "Input" );
245 g_pinTypes[ELECTRICAL_PINTYPE::PT_OUTPUT].name = _( "Output" );
246 g_pinTypes[ELECTRICAL_PINTYPE::PT_BIDI].name = _( "Bidirectional" );
247 g_pinTypes[ELECTRICAL_PINTYPE::PT_TRISTATE].name = _( "Tri-state" );
248 g_pinTypes[ELECTRICAL_PINTYPE::PT_PASSIVE].name = _( "Passive" );
249 g_pinTypes[ELECTRICAL_PINTYPE::PT_NIC].name = _( "Free" );
250 g_pinTypes[ELECTRICAL_PINTYPE::PT_UNSPECIFIED].name = _( "Unspecified" );
251 g_pinTypes[ELECTRICAL_PINTYPE::PT_POWER_IN].name = _( "Power input" );
252 g_pinTypes[ELECTRICAL_PINTYPE::PT_POWER_OUT].name = _( "Power output" );
253 g_pinTypes[ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR].name = _( "Open collector" );
254 g_pinTypes[ELECTRICAL_PINTYPE::PT_OPENEMITTER].name = _( "Open emitter" );
255 g_pinTypes[ELECTRICAL_PINTYPE::PT_NC].name = _( "Unconnected" );
256
257 g_pinTypesLanguage = Pgm().GetSelectedLanguageIdentifier();
258 }
259
260 auto findIt = g_pinTypes.find( aType );
261
262 wxCHECK_MSG( findIt != g_pinTypes.end(), wxT( "???" ), wxT( "Pin type not found!" ) );
263
264 return findIt->second.name;
265}
266
267
269{
270 auto findIt = g_pinTypes.find( aType );
271
272 wxCHECK_MSG( findIt != g_pinTypes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
273
274 return findIt->second.bitmap;
275}
276
277
279{
280 auto findIt = pinShapes.find( aShape );
281
282 wxCHECK_MSG( findIt != pinShapes.end(), wxT( "?" ), wxT( "Pin type not found!" ) );
283
284 return findIt->second.name;
285}
286
287
289{
290 auto findIt = pinShapes.find( aShape );
291
292 wxCHECK_MSG( findIt != pinShapes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
293
294 return findIt->second.bitmap;
295}
296
297
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)
@ PIN_LEFT
Definition: lib_pin.h:47
@ PIN_RIGHT
Definition: lib_pin.h:46
@ PIN_UP
Definition: lib_pin.h:48
@ PIN_DOWN
Definition: lib_pin.h:49
see class PGM_BASE
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:195
static const int pin_orientation_codes[]
Definition: pin_type.cpp:92
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:119
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:288
int PinOrientationIndex(int code)
Definition: pin_type.cpp:150
static const BITMAPS iconsPinsOrientations[]
Definition: pin_type.cpp:103
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:186
static std::vector< BITMAPS > g_orientationIcons
Definition: pin_type.cpp:40
static std::vector< BITMAPS > g_typeIcons
Definition: pin_type.cpp:34
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:240
int g_pinTypesLanguage
Definition: pin_type.cpp:67
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:204
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:213
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:268
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:278
const wxArrayString & PinOrientationNames()
Definition: pin_type.cpp:222
const std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > pinShapes
Definition: pin_type.cpp:78
#define PIN_ORIENTATION_CNT
Definition: pin_type.cpp:112
static std::vector< BITMAPS > g_shapeIcons
Definition: pin_type.cpp:37
static wxArrayString g_orientationNames
Definition: pin_type.cpp:41
int PinOrientationCode(int index)
Definition: pin_type.cpp:141
void InitTables()
Definition: pin_type.cpp:164
const std::vector< BITMAPS > & PinOrientationIcons()
Definition: pin_type.cpp:231
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
GRAPHIC_PINSHAPE
Definition: pin_type.h:56
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
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