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-2021 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 
30 
31 // These are true singletons so it's OK for them to be globals.
32 
33 static std::vector<BITMAPS> g_typeIcons;
34 static wxArrayString g_typeNames;
35 
36 static std::vector<BITMAPS> g_shapeIcons;
37 static wxArrayString g_shapeNames;
38 
39 static std::vector<BITMAPS> g_orientationIcons;
40 static wxArrayString g_orientationNames;
41 
42 
44 {
45  wxString name;
47 };
48 
49 // clang-format off
50 const std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> pinTypes = {
53  { ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), BITMAPS::pintype_bidi } },
62  { ELECTRICAL_PINTYPE::PT_NC, { _( "Unconnected" ), BITMAPS::pintype_noconnect } },
63 };
64 // clang-format on
65 
66 
68 {
69  wxString name;
71 };
72 
73 
74 // clang-format off
75 const std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> pinShapes = {
85 };
86 // clang-format on
87 
88 
89 static const int pin_orientation_codes[] =
90 {
91  PIN_RIGHT,
92  PIN_LEFT,
93  PIN_UP,
94  PIN_DOWN
95 };
96 
97 
98 // bitmaps to show pins orientations in dialog editor
99 // must have same order than pin_orientation_names
101 {
106 };
107 
108 
109 #define PIN_ORIENTATION_CNT arrayDim( pin_orientation_codes )
110 
111 
112 // Helper functions to get the pin orientation name from pin_orientation_codes
113 // Note: the strings are *not* static because they are translated and must be built
114 // on the fly, to be properly translated
115 
116 wxString PinOrientationName( unsigned aPinOrientationCode )
117 {
118  /* Note: The following name lists are sentence capitalized per the GNOME UI
119  * standards for list controls. Please do not change the capitalization
120  * of these strings unless the GNOME UI standards are changed.
121  */
122  const wxString pin_orientation_names[] =
123  {
124  _( "Right" ),
125  _( "Left" ),
126  _( "Up" ),
127  _( "Down" ),
128  wxT( "???" )
129  };
130 
131  if( aPinOrientationCode > PIN_ORIENTATION_CNT )
132  aPinOrientationCode = PIN_ORIENTATION_CNT;
133 
134  return pin_orientation_names[ aPinOrientationCode ];
135 }
136 
137 
138 int PinOrientationCode( int index )
139 {
140  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
141  return pin_orientation_codes[ index ];
142 
143  return PIN_RIGHT;
144 }
145 
146 
147 int PinOrientationIndex( int code )
148 {
149  size_t i;
150 
151  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
152  {
153  if( pin_orientation_codes[i] == code )
154  return (int) i;
155  }
156 
157  return wxNOT_FOUND;
158 }
159 
160 
162 {
163  for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
164  {
165  g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
166  g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
167  }
168 
169  for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
170  {
171  g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
172  g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
173  }
174 
175  for( unsigned i = 0; i < PIN_ORIENTATION_CNT; ++i )
176  {
177  g_orientationIcons.push_back( iconsPinsOrientations[ i ] );
178  g_orientationNames.push_back( PinOrientationName( i ) );
179  }
180 }
181 
182 
183 const wxArrayString& PinTypeNames()
184 {
185  if( g_typeNames.empty() )
186  InitTables();
187 
188  return g_typeNames;
189 }
190 
191 
192 const std::vector<BITMAPS>& PinTypeIcons()
193 {
194  if( g_typeIcons.empty() )
195  InitTables();
196 
197  return g_typeIcons;
198 }
199 
200 
201 const wxArrayString& PinShapeNames()
202 {
203  if( g_shapeNames.empty() )
204  InitTables();
205 
206  return g_shapeNames;
207 }
208 
209 
210 const std::vector<BITMAPS>& PinShapeIcons()
211 {
212  if( g_shapeIcons.empty() )
213  InitTables();
214 
215  return g_shapeIcons;
216 }
217 
218 
219 const wxArrayString& PinOrientationNames()
220 {
221  if( g_orientationNames.empty() )
222  InitTables();
223 
224  return g_orientationNames;
225 }
226 
227 
228 const std::vector<BITMAPS>& PinOrientationIcons()
229 {
230  if( g_orientationIcons.empty() )
231  InitTables();
232 
233  return g_orientationIcons;
234 }
235 
236 
238 {
239  auto findIt = pinTypes.find( aType );
240 
241  wxCHECK_MSG( findIt != pinTypes.end(), wxT( "???" ), "Could not find pin type in lookup map" );
242 
243  return findIt->second.name;
244 }
245 
246 
248 {
249  auto findIt = pinTypes.find( aType );
250 
251  wxCHECK_MSG( findIt != pinTypes.end(), BITMAPS::INVALID_BITMAP,
252  "Could not find pin type in lookup map" );
253 
254  return findIt->second.bitmap;
255 }
256 
257 
259 {
260  auto findIt = pinShapes.find( aShape );
261 
262  wxCHECK_MSG( findIt != pinShapes.end(), wxT( "?" ), "Could not find pinshape in lookup map" );
263 
264  return findIt->second.name;
265 }
266 
267 
269 {
270  auto findIt = pinShapes.find( aShape );
271 
272  wxCHECK_MSG( findIt != pinShapes.end(), BITMAPS::INVALID_BITMAP,
273  "Could not find pinshape in lookup map" );
274 
275  return findIt->second.bitmap;
276 }
277 
278 
power input (GND, VCC for ICs). Must be connected to a power output.
const std::vector< BITMAPS > & PinOrientationIcons()
Definition: pin_type.cpp:228
static std::vector< BITMAPS > g_typeIcons
Definition: pin_type.cpp:33
#define PIN_ORIENTATION_CNT
Definition: pin_type.cpp:109
void InitTables()
Definition: pin_type.cpp:161
const std::vector< BITMAPS > & PinShapeIcons()
Definition: pin_type.cpp:210
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:237
pin for passive symbols: must be connected, and can be connected to any pin
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:247
unknown electrical properties: creates always a warning when connected
int PinOrientationIndex(int code)
Definition: pin_type.cpp:147
int PinOrientationCode(int index)
Definition: pin_type.cpp:138
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:258
Definition: lib_pin.h:48
wxString name
Definition: pin_type.cpp:69
GRAPHIC_PINSHAPE
Definition: pin_type.h:55
static std::vector< BITMAPS > g_orientationIcons
Definition: pin_type.cpp:39
static const int pin_orientation_codes[]
Definition: pin_type.cpp:89
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:116
not internally connected (may be connected to anything)
static std::vector< BITMAPS > g_shapeIcons
Definition: pin_type.cpp:36
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:201
const std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > pinShapes
Definition: pin_type.cpp:75
#define GRAPHIC_PINSHAPES_TOTAL
Definition: pin_type.h:70
const std::map< ELECTRICAL_PINTYPE, struct pinTypeStruct > pinTypes
Definition: pin_type.cpp:50
wxString name
Definition: pin_type.cpp:45
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:183
#define _(s)
BITMAPS bitmap
Definition: pin_type.cpp:70
static wxArrayString g_shapeNames
Definition: pin_type.cpp:37
const wxArrayString & PinOrientationNames()
Definition: pin_type.cpp:219
static wxArrayString g_orientationNames
Definition: pin_type.cpp:40
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:35
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:268
usual pin input: must be connected
input or output (like port for a microprocessor)
static wxArrayString g_typeNames
Definition: pin_type.cpp:34
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:53
not connected (must be left open)
BITMAPS bitmap
Definition: pin_type.cpp:46
output of a regulator: intended to be connected to power input pins
static const BITMAPS iconsPinsOrientations[]
Definition: pin_type.cpp:100
const std::vector< BITMAPS > & PinTypeIcons()
Definition: pin_type.cpp:192