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, 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( "???" ),
215 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
216
217 return it->second.name;
218}
219
220
222{
223 if( g_pinElectricalTypes.empty() )
224 InitTables();
225
226 auto it = g_pinElectricalTypes.find( aType );
227
228 wxCHECK_MSG( it != g_pinElectricalTypes.end(), BITMAPS::INVALID_BITMAP,
229 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
230
231 return it->second.bitmap;
232}
233
234
236{
237 if( g_pinShapes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
238 InitTables();
239
240 auto it = g_pinShapes.find( aShape );
241
242 wxCHECK_MSG( it != g_pinShapes.end(), wxT( "?" ),
243 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
244
245 return it->second.name;
246}
247
248
250{
251 if( g_pinShapes.empty() )
252 InitTables();
253
254 auto it = g_pinShapes.find( aShape );
255
256 wxCHECK_MSG( it != g_pinShapes.end(), BITMAPS::INVALID_BITMAP,
257 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
258
259 return it->second.bitmap;
260}
261
262
263wxString PinOrientationName( PIN_ORIENTATION aOrientation )
264{
265 if( g_pinOrientations.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
266 InitTables();
267
268 auto it = g_pinOrientations.find( aOrientation );
269
270 wxCHECK_MSG( it != g_pinOrientations.end(), wxT( "?" ),
271 wxString::Format( "Pin orientation not found for type %d!", (int) aOrientation ) );
272
273 return it->second.name;
274}
275
276
278{
279 if( g_pinOrientations.empty() )
280 InitTables();
281
282 auto it = g_pinOrientations.find( aOrientation );
283
284 wxCHECK_MSG( it != g_pinOrientations.end(), BITMAPS::INVALID_BITMAP,
285 wxString::Format( "Pin orientation not found for type %d!", (int) aOrientation ) );
286
287 return it->second.bitmap;
288}
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:229
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:913
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:249
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:221
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition pin_type.cpp:235
const wxArrayString & PinOrientationNames()
Definition pin_type.cpp:189
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition pin_type.cpp:263
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:277
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
Definition pin_type.h:37
@ PT_NC
not connected (must be left open)
Definition pin_type.h:50
@ PT_OUTPUT
usual output
Definition pin_type.h:38
@ PT_TRISTATE
tri state bus pin
Definition pin_type.h:40
@ PT_NIC
not internally connected (may be connected to anything)
Definition pin_type.h:44
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:39
@ PT_OPENEMITTER
pin type open emitter
Definition pin_type.h:49
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
Definition pin_type.h:47
@ PT_OPENCOLLECTOR
pin type open collector
Definition pin_type.h:48
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:46
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:45
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:43
#define ELECTRICAL_PINTYPES_TOTAL
Definition pin_type.h:56
#define GRAPHIC_PINSHAPES_TOTAL
Definition pin_type.h:99
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:105
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
Definition pin_type.h:127
@ PIN_RIGHT
The pin extends rightwards from the connection point.
Definition pin_type.h:111
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
Definition pin_type.h:118
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition pin_type.h:135
GRAPHIC_PINSHAPE
Definition pin_type.h:84
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