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 <pin_type.h>
25 #include <lib_pin.h>
26 #include <core/arraydim.h>
27 
28 
29 // These are true singletons so it's OK for them to be globals.
30 
31 static std::vector<BITMAP_DEF> g_typeIcons;
32 static wxArrayString g_typeNames;
33 
34 static std::vector<BITMAP_DEF> g_shapeIcons;
35 static wxArrayString g_shapeNames;
36 
37 static std::vector<BITMAP_DEF> g_orientationIcons;
38 static wxArrayString g_orientationNames;
39 
40 
42 {
43  wxString name;
45 };
46 
47 // clang-format off
48 const std::map<ELECTRICAL_PINTYPE, struct pinTypeStruct> pinTypes = {
51  { ELECTRICAL_PINTYPE::PT_BIDI, { _( "Bidirectional" ), pintype_bidi_xpm } },
52  { ELECTRICAL_PINTYPE::PT_TRISTATE, { _( "Tri-state" ), pintype_3states_xpm } },
54  { ELECTRICAL_PINTYPE::PT_NIC, { _( "Free" ), pintype_nic_xpm } },
56  { ELECTRICAL_PINTYPE::PT_POWER_IN, { _( "Power input" ), pintype_powerinput_xpm } },
58  { ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR,{ _( "Open collector" ), pintype_opencoll_xpm } },
59  { ELECTRICAL_PINTYPE::PT_OPENEMITTER, { _( "Open emitter" ), pintype_openemit_xpm } },
60  { ELECTRICAL_PINTYPE::PT_NC, { _( "Unconnected" ), pintype_noconnect_xpm } },
61 };
62 // clang-format on
63 
64 
66 {
67  wxString name;
69 };
70 
71 
72 // clang-format off
73 const std::map<GRAPHIC_PINSHAPE, struct pinShapeStruct> pinShapes = {
74  { GRAPHIC_PINSHAPE::LINE, { _( "Line" ), pinshape_normal_xpm } },
75  { GRAPHIC_PINSHAPE::INVERTED, { _( "Inverted" ), pinshape_invert_xpm } },
77  { GRAPHIC_PINSHAPE::INVERTED_CLOCK, { _( "Inverted clock" ), pinshape_clock_invert_xpm } },
81  { GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, { _( "Falling edge clock" ), pinshape_clock_fall_xpm } },
82  { GRAPHIC_PINSHAPE::NONLOGIC, { _( "NonLogic" ), pinshape_nonlogic_xpm } },
83 };
84 // clang-format on
85 
86 
87 static const int pin_orientation_codes[] =
88 {
89  PIN_RIGHT,
90  PIN_LEFT,
91  PIN_UP,
92  PIN_DOWN
93 };
94 
95 
96 // bitmaps to show pins orientations in dialog editor
97 // must have same order than pin_orientation_names
99 {
104 };
105 
106 
107 #define PIN_ORIENTATION_CNT arrayDim( pin_orientation_codes )
108 
109 
110 // Helper functions to get the pin orientation name from pin_orientation_codes
111 // Note: the strings are *not* static because they are translated and must be built
112 // on the fly, to be properly translated
113 
114 wxString PinOrientationName( unsigned aPinOrientationCode )
115 {
116  /* Note: The following name lists are sentence capitalized per the GNOME UI
117  * standards for list controls. Please do not change the capitalization
118  * of these strings unless the GNOME UI standards are changed.
119  */
120  const wxString pin_orientation_names[] =
121  {
122  _( "Right" ),
123  _( "Left" ),
124  _( "Up" ),
125  _( "Down" ),
126  wxT( "???" )
127  };
128 
129  if( aPinOrientationCode > PIN_ORIENTATION_CNT )
130  aPinOrientationCode = PIN_ORIENTATION_CNT;
131 
132  return pin_orientation_names[ aPinOrientationCode ];
133 }
134 
135 
136 int PinOrientationCode( int index )
137 {
138  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
139  return pin_orientation_codes[ index ];
140 
141  return PIN_RIGHT;
142 }
143 
144 
145 int PinOrientationIndex( int code )
146 {
147  size_t i;
148 
149  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
150  {
151  if( pin_orientation_codes[i] == code )
152  return (int) i;
153  }
154 
155  return wxNOT_FOUND;
156 }
157 
158 
160 {
161  for( unsigned i = 0; i < ELECTRICAL_PINTYPES_TOTAL; ++i )
162  {
163  g_typeIcons.push_back( ElectricalPinTypeGetBitmap( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
164  g_typeNames.push_back( ElectricalPinTypeGetText( static_cast<ELECTRICAL_PINTYPE>( i ) ) );
165  }
166 
167  for( unsigned i = 0; i < GRAPHIC_PINSHAPES_TOTAL; ++i )
168  {
169  g_shapeIcons.push_back( PinShapeGetBitmap( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
170  g_shapeNames.push_back( PinShapeGetText( static_cast<GRAPHIC_PINSHAPE>( i ) ) );
171  }
172 
173  for( unsigned i = 0; i < PIN_ORIENTATION_CNT; ++i )
174  {
175  g_orientationIcons.push_back( iconsPinsOrientations[ i ] );
176  g_orientationNames.push_back( PinOrientationName( i ) );
177  }
178 }
179 
180 
181 const wxArrayString& PinTypeNames()
182 {
183  if( g_typeNames.empty() )
184  InitTables();
185 
186  return g_typeNames;
187 }
188 
189 
190 const std::vector<BITMAP_DEF>& PinTypeIcons()
191 {
192  if( g_typeIcons.empty() )
193  InitTables();
194 
195  return g_typeIcons;
196 }
197 
198 
199 const wxArrayString& PinShapeNames()
200 {
201  if( g_shapeNames.empty() )
202  InitTables();
203 
204  return g_shapeNames;
205 }
206 
207 
208 const std::vector<BITMAP_DEF>& PinShapeIcons()
209 {
210  if( g_shapeIcons.empty() )
211  InitTables();
212 
213  return g_shapeIcons;
214 }
215 
216 
217 const wxArrayString& PinOrientationNames()
218 {
219  if( g_orientationNames.empty() )
220  InitTables();
221 
222  return g_orientationNames;
223 }
224 
225 
226 const std::vector<BITMAP_DEF>& PinOrientationIcons()
227 {
228  if( g_orientationIcons.empty() )
229  InitTables();
230 
231  return g_orientationIcons;
232 }
233 
234 
236 {
237  auto findIt = pinTypes.find( aType );
238 
239  wxCHECK_MSG( findIt != pinTypes.end(), wxT( "???" ), "Could not find pin type in lookup map" );
240 
241  return findIt->second.name;
242 }
243 
244 
246 {
247  auto findIt = pinTypes.find( aType );
248 
249  wxCHECK_MSG( findIt != pinTypes.end(), nullptr, "Could not find pin type in lookup map" );
250 
251  return findIt->second.bitmap;
252 }
253 
254 
256 {
257  auto findIt = pinShapes.find( aShape );
258 
259  wxCHECK_MSG( findIt != pinShapes.end(), wxT( "?" ), "Could not find pinshape in lookup map" );
260 
261  return findIt->second.name;
262 }
263 
264 
266 {
267  auto findIt = pinShapes.find( aShape );
268 
269  wxCHECK_MSG( findIt != pinShapes.end(), nullptr, "Could not find pinshape in lookup map" );
270 
271  return findIt->second.bitmap;
272 }
273 
274 
const BITMAP_OPAQUE pintype_bidi_xpm[1]
power input (GND, VCC for ICs). Must be connected to a power output.
const BITMAP_OPAQUE pinshape_active_low_input_xpm[1]
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const BITMAP_OPAQUE pintype_openemit_xpm[1]
#define PIN_ORIENTATION_CNT
Definition: pin_type.cpp:107
void InitTables()
Definition: pin_type.cpp:159
const std::vector< BITMAP_DEF > & PinOrientationIcons()
Definition: pin_type.cpp:226
const BITMAP_OPAQUE pinshape_normal_xpm[1]
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:235
const BITMAP_OPAQUE pinshape_active_low_output_xpm[1]
const std::vector< BITMAP_DEF > & PinTypeIcons()
Definition: pin_type.cpp:190
const BITMAP_OPAQUE * bitmap
Definition: pin_type.cpp:68
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
int PinOrientationIndex(int code)
Definition: pin_type.cpp:145
const BITMAP_OPAQUE pinshape_clock_invert_xpm[1]
int PinOrientationCode(int index)
Definition: pin_type.cpp:136
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:255
Definition: lib_pin.h:50
const BITMAP_OPAQUE pintype_notspecif_xpm[1]
wxString name
Definition: pin_type.cpp:67
GRAPHIC_PINSHAPE
Definition: pin_type.h:54
static std::vector< BITMAP_DEF > g_orientationIcons
Definition: pin_type.cpp:37
const BITMAP_OPAQUE pinshape_clock_fall_xpm[1]
const BITMAP_OPAQUE pinorient_up_xpm[1]
const BITMAP_OPAQUE * bitmap
Definition: pin_type.cpp:44
const std::vector< BITMAP_DEF > & PinShapeIcons()
Definition: pin_type.cpp:208
static const int pin_orientation_codes[]
Definition: pin_type.cpp:87
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:114
not internally connected (may be connected to anything)
const BITMAP_OPAQUE pintype_noconnect_xpm[1]
const wxArrayString & PinShapeNames()
Definition: pin_type.cpp:199
const std::map< GRAPHIC_PINSHAPE, struct pinShapeStruct > pinShapes
Definition: pin_type.cpp:73
static std::vector< BITMAP_DEF > g_shapeIcons
Definition: pin_type.cpp:34
const BITMAP_OPAQUE pintype_powerinput_xpm[1]
#define GRAPHIC_PINSHAPES_TOTAL
Definition: pin_type.h:69
const BITMAP_OPAQUE pinshape_invert_xpm[1]
const std::map< ELECTRICAL_PINTYPE, struct pinTypeStruct > pinTypes
Definition: pin_type.cpp:48
wxString name
Definition: pin_type.cpp:43
const BITMAP_OPAQUE pinorient_right_xpm[1]
const BITMAP_OPAQUE pinshape_clock_normal_xpm[1]
const wxArrayString & PinTypeNames()
Definition: pin_type.cpp:181
const BITMAP_OPAQUE pintype_nic_xpm[1]
Definition: pintype_nic.cpp:18
const BITMAP_OPAQUE pintype_passive_xpm[1]
static wxArrayString g_shapeNames
Definition: pin_type.cpp:35
const BITMAP_OPAQUE pinshape_clock_active_low_xpm[1]
static const BITMAP_DEF iconsPinsOrientations[]
Definition: pin_type.cpp:98
const wxArrayString & PinOrientationNames()
Definition: pin_type.cpp:217
BITMAP_DEF ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:245
const BITMAP_OPAQUE pintype_3states_xpm[1]
const BITMAP_OPAQUE pinshape_nonlogic_xpm[1]
static wxArrayString g_orientationNames
Definition: pin_type.cpp:38
BITMAP_DEF PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:265
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:34
#define _(s)
Definition: 3d_actions.cpp:33
usual pin input: must be connected
static std::vector< BITMAP_DEF > g_typeIcons
Definition: pin_type.cpp:31
input or output (like port for a microprocessor)
const BITMAP_OPAQUE pintype_poweroutput_xpm[1]
static wxArrayString g_typeNames
Definition: pin_type.cpp:32
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:52
const BITMAP_OPAQUE pintype_opencoll_xpm[1]
not connected (must be left open)
const BITMAP_OPAQUE pinorient_down_xpm[1]
const BITMAP_OPAQUE pinorient_left_xpm[1]
const BITMAP_OPAQUE pintype_input_xpm[1]
output of a regulator: intended to be connected to power input pins
const BITMAP_OPAQUE pintype_output_xpm[1]