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 <magic_enum.hpp>
27#include <sch_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
50{
51 wxString name;
53};
54
55static std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> g_pinElectricalTypes;
56static std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> g_pinShapes;
57static std::map<PIN_ORIENTATION, struct pinShapeStruct> g_pinOrientations;
58
59
60static int g_language = wxLANGUAGE_UNKNOWN;
61
62
64{
65 wxASSERT( index < magic_enum::enum_count<PIN_ORIENTATION>() );
66 return magic_enum::enum_value<PIN_ORIENTATION>( index );
67}
68
69
71{
72 auto index = magic_enum::enum_index<PIN_ORIENTATION>( code );
73
74 if( index.has_value() )
75 return index.value();
76
77 return wxNOT_FOUND;
78}
79
80
82{
83 // clang-format off
87 { ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), BITMAPS::pintype_bidi } },
97 };
98
99 g_pinShapes = {
109 };
110
116 };
117 // clang-format on
118
120
121 g_typeIcons.clear();
122 g_typeNames.clear();
123
124 for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
125 {
126 g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
127 g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
128 }
129
130 g_shapeIcons.clear();
131 g_shapeNames.clear();
132
133 for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
134 {
135 g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
136 g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
137 }
138
139 g_orientationIcons.clear();
140 g_orientationNames.clear();
141
142 for( PIN_ORIENTATION orientation : magic_enum::enum_values<PIN_ORIENTATION>() )
143 {
144 if( orientation != PIN_ORIENTATION::INHERIT )
145 {
146 g_orientationIcons.push_back( PinOrientationGetBitmap( orientation ) );
147 g_orientationNames.push_back( PinOrientationName( orientation ) );
148 }
149 }
150}
151
152
153const wxArrayString& PinTypeNames()
154{
155 if( g_typeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
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() || g_language != Pgm().GetSelectedLanguageIdentifier() )
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() || g_language != Pgm().GetSelectedLanguageIdentifier() )
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_pinElectricalTypes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
210 InitTables();
211
212 auto it = g_pinElectricalTypes.find( aType );
213
214 wxCHECK_MSG( it != g_pinElectricalTypes.end(), wxT( "???" ), wxT( "Pin type not found!" ) );
215
216 return it->second.name;
217}
218
219
221{
222 if( g_pinElectricalTypes.empty() )
223 InitTables();
224
225 auto it = g_pinElectricalTypes.find( aType );
226
227 wxCHECK_MSG( it != g_pinElectricalTypes.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin type not found!" ) );
228
229 return it->second.bitmap;
230}
231
232
234{
235 if( g_pinShapes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
236 InitTables();
237
238 auto it = g_pinShapes.find( aShape );
239
240 wxCHECK_MSG( it != g_pinShapes.end(), wxT( "?" ), wxT( "Pin type not found!" ) );
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, wxT( "Pin type not found!" ) );
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( "?" ), wxT( "Pin orientation not found!" ) );
267
268 return it->second.name;
269}
270
271
273{
274 if( g_pinOrientations.empty() )
275 InitTables();
276
277 auto it = g_pinOrientations.find( aOrientation );
278
279 wxCHECK_MSG( it != g_pinOrientations.end(), BITMAPS::INVALID_BITMAP, wxT( "Pin orientation not found!" ) );
280
281 return it->second.bitmap;
282}
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
virtual int GetSelectedLanguageIdentifier() const
Definition: pgm_base.h:238
#define _(s)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:162
static std::map< PIN_ORIENTATION, struct pinShapeStruct > g_pinOrientations
Definition: pin_type.cpp:57
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:246
static int g_language
Definition: pin_type.cpp:60
static std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > g_pinShapes
Definition: pin_type.cpp:56
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:153
static std::vector< BITMAPS > g_orientationIcons
Definition: pin_type.cpp:39
static std::vector< BITMAPS > g_typeIcons
Definition: pin_type.cpp:33
int PinOrientationIndex(PIN_ORIENTATION code)
Definition: pin_type.cpp:70
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:207
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:171
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:180
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:220
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:233
const wxArrayString & PinOrientationNames()
Definition: pin_type.cpp:189
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:259
static std::vector< BITMAPS > g_shapeIcons
Definition: pin_type.cpp:36
static wxArrayString g_orientationNames
Definition: pin_type.cpp:40
BITMAPS PinOrientationGetBitmap(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:272
static std::map< ELECTRICAL_PINTYPE, struct pinTypeStruct > g_pinElectricalTypes
Definition: pin_type.cpp:55
void InitTables()
Definition: pin_type.cpp:81
PIN_ORIENTATION PinOrientationCode(size_t index)
Definition: pin_type.cpp:63
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:54
#define GRAPHIC_PINSHAPES_TOTAL
Definition: pin_type.h:72
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:78
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
GRAPHIC_PINSHAPE
Definition: pin_type.h:57
wxString name
Definition: pin_type.cpp:51
BITMAPS bitmap
Definition: pin_type.cpp:52
wxString name
Definition: pin_type.cpp:45
BITMAPS bitmap
Definition: pin_type.cpp:46