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