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 } },
94 { ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, { _( "Open collector" ),
98 };
99
100 g_pinShapes = {
104 { GRAPHIC_PINSHAPE::INVERTED_CLOCK, { _( "Inverted clock" ),
108 { GRAPHIC_PINSHAPE::OUTPUT_LOW, { _( "Output low" ),
110 { GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, { _( "Falling edge clock" ),
112 { GRAPHIC_PINSHAPE::NONLOGIC, { _( "NonLogic" ),
114 };
115
121 };
122 // clang-format on
123
125
126 g_typeIcons.clear();
127 g_typeNames.clear();
128
129 for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
130 {
131 g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
132 g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
133 }
134
135 g_shapeIcons.clear();
136 g_shapeNames.clear();
137
138 for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
139 {
140 g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
141 g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
142 }
143
144 g_orientationIcons.clear();
145 g_orientationNames.clear();
146
147 for( PIN_ORIENTATION orientation : magic_enum::enum_values<PIN_ORIENTATION>() )
148 {
149 if( orientation != PIN_ORIENTATION::INHERIT )
150 {
151 g_orientationIcons.push_back( PinOrientationGetBitmap( orientation ) );
152 g_orientationNames.push_back( PinOrientationName( orientation ) );
153 }
154 }
155}
156
157
158const wxArrayString& PinTypeNames()
159{
160 if( g_typeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
161 InitTables();
162
163 return g_typeNames;
164}
165
166
167const std::vector<BITMAPS>& PinTypeIcons()
168{
169 if( g_typeIcons.empty() )
170 InitTables();
171
172 return g_typeIcons;
173}
174
175
176const wxArrayString& PinShapeNames()
177{
178 if( g_shapeNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
179 InitTables();
180
181 return g_shapeNames;
182}
183
184
185const std::vector<BITMAPS>& PinShapeIcons()
186{
187 if( g_shapeIcons.empty() )
188 InitTables();
189
190 return g_shapeIcons;
191}
192
193
194const wxArrayString& PinOrientationNames()
195{
196 if( g_orientationNames.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
197 InitTables();
198
199 return g_orientationNames;
200}
201
202
203const std::vector<BITMAPS>& PinOrientationIcons()
204{
205 if( g_orientationIcons.empty() )
206 InitTables();
207
208 return g_orientationIcons;
209}
210
211
213{
214 if( g_pinElectricalTypes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
215 InitTables();
216
217 auto it = g_pinElectricalTypes.find( aType );
218
219 wxCHECK_MSG( it != g_pinElectricalTypes.end(), wxT( "???" ),
220 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
221
222 return it->second.name;
223}
224
225
227{
228 if( g_pinElectricalTypes.empty() )
229 InitTables();
230
231 auto it = g_pinElectricalTypes.find( aType );
232
233 wxCHECK_MSG( it != g_pinElectricalTypes.end(), BITMAPS::INVALID_BITMAP,
234 wxString::Format( "Pin type not found for type %d!", (int) aType ) );
235
236 return it->second.bitmap;
237}
238
239
241{
242 if( g_pinShapes.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
243 InitTables();
244
245 auto it = g_pinShapes.find( aShape );
246
247 wxCHECK_MSG( it != g_pinShapes.end(), wxT( "?" ),
248 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
249
250 return it->second.name;
251}
252
253
255{
256 if( g_pinShapes.empty() )
257 InitTables();
258
259 auto it = g_pinShapes.find( aShape );
260
261 wxCHECK_MSG( it != g_pinShapes.end(), BITMAPS::INVALID_BITMAP,
262 wxString::Format( "Pin shape not found for type %d!", (int) aShape ) );
263
264 return it->second.bitmap;
265}
266
267
268wxString PinOrientationName( PIN_ORIENTATION aOrientation )
269{
270 if( g_pinOrientations.empty() || g_language != Pgm().GetSelectedLanguageIdentifier() )
271 InitTables();
272
273 auto it = g_pinOrientations.find( aOrientation );
274
275 wxCHECK_MSG( it != g_pinOrientations.end(), wxT( "?" ),
276 wxString::Format( "Pin orientation not found for type %d!", (int) aOrientation ) );
277
278 return it->second.name;
279}
280
281
283{
284 if( g_pinOrientations.empty() )
285 InitTables();
286
287 auto it = g_pinOrientations.find( aOrientation );
288
289 wxCHECK_MSG( it != g_pinOrientations.end(), BITMAPS::INVALID_BITMAP,
290 wxString::Format( "Pin orientation not found for type %d!", (int) aOrientation ) );
291
292 return it->second.bitmap;
293}
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:229
#define _(s)
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:167
static std::map< PIN_ORIENTATION, struct pinShapeStruct > g_pinOrientations
Definition: pin_type.cpp:57
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:254
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:158
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:212
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:176
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:185
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:226
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:240
const wxArrayString & PinOrientationNames()
Definition: pin_type.cpp:194
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:268
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:282
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:203
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
tri 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:56
#define GRAPHIC_PINSHAPES_TOTAL
Definition: pin_type.h:74
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:80
@ 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:59
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