KiCad PCB EDA Suite
lib_pin.h
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) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
5 * Copyright (C) 2015 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26
27#ifndef CLASS_PIN_H
28#define CLASS_PIN_H
29
30#include <lib_item.h>
31#include <pin_type.h>
32#include <lib_symbol.h>
33
34// Circle diameter drawn at the active end of pins:
35#define TARGET_PIN_RADIUS schIUScale.MilsToIU( 15 )
36
37// Pin visibility flag bit:
38#define PIN_INVISIBLE 1 // Set makes pin invisible
39
40
45 PIN_RIGHT = 'R',
46 PIN_LEFT = 'L',
47 PIN_UP = 'U',
48 PIN_DOWN = 'D'
49};
50
51
52class LIB_PIN : public LIB_ITEM
53{
54public:
55 struct ALT
56 {
57 wxString m_Name;
58 GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin
59 ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin.
60 };
61
63
64 wxString GetClass() const override
65 {
66 return wxT( "LIB_PIN" );
67 }
68
69 wxString GetTypeName() const override
70 {
71 return _( "Pin" );
72 }
73
74 int GetOrientation() const { return m_orientation; }
75 void SetOrientation( int aOrientation ) { m_orientation = aOrientation; }
76
77 GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
78 void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
79
80 int GetLength() const { return m_length; }
81 void SetLength( int aLength ) { m_length = aLength; }
82
88 void ChangeLength( int aLength );
89
90 ELECTRICAL_PINTYPE GetType() const { return m_type; }
91 void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; }
92
93 wxString const GetCanonicalElectricalTypeName() const
94 {
96 }
97
98 wxString const GetElectricalTypeName() const
99 {
101 }
102
103 bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
104 void SetVisible( bool aVisible )
105 {
106 if( aVisible )
107 m_attributes &= ~PIN_INVISIBLE;
108 else
110 }
111
112 const wxString& GetName() const { return m_name; }
113 wxString GetShownName() const;
114 void SetName( const wxString& aName )
115 {
116 m_name = aName;
117
118 // pin name string does not support spaces
119 m_name.Replace( wxT( " " ), wxT( "_" ) );
120 }
121
122 const wxString& GetNumber() const { return m_number; }
123 wxString GetShownNumber() const { return m_number; }
124 void SetNumber( const wxString& aNumber )
125 {
126 m_number = aNumber;
127
128 // pin number string does not support spaces
129 m_number.Replace( wxT( " " ), wxT( "_" ) );
130 }
131
132 int GetNameTextSize() const { return m_nameTextSize; }
133 void SetNameTextSize( int aSize ) { m_nameTextSize = aSize; }
134
135 int GetNumberTextSize() const { return m_numTextSize; }
136 void SetNumberTextSize( int aSize ) { m_numTextSize = aSize; }
137
138 std::map<wxString, ALT>& GetAlternates() { return m_alternates; }
139
140 ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; }
141
150 void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
151 const TRANSFORM& aTransform, bool aDimmed ) override;
152
159 int PinDrawOrient( const TRANSFORM& aTransform ) const;
160
161 LIB_PIN( LIB_SYMBOL* aParent );
162
163 LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber, int aOrientation,
164 ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize, int aNumTextSize,
165 int aConvert, const VECTOR2I& aPos, int aUnit );
166
167 // Do not create a copy constructor. The one generated by the compiler is adequate.
168
169 // No, LIB_PINs don't really have operating poinst. But we draw SCH_PINs through their LIB_PIN
170 // counterparts, so here we are....
171 const wxString& GetOperatingPoint() const { return m_operatingPoint; }
172 void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
173
174#if defined(DEBUG)
175 void Show( int nestLevel, std::ostream& os ) const override;
176#endif
177
178 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
179
180 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
181
182 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
183
184 const BOX2I ViewBBox() const override;
185
186 void ViewGetLayers( int aLayers[], int& aCount ) const override;
187
188 /* Cannot use a default parameter here as it will not be compatible with the virtual. */
189 const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); }
190
195 const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
196 bool aIncludeElectricalType ) const;
197
203 bool IsGlobalPower() const
204 {
206 && ( !IsVisible() || (LIB_SYMBOL*) GetParent()->IsPower() );
207 }
208
209 int GetPenWidth() const override;
210
218 void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPinOrient, int aTextInside,
219 bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const;
220
221 void PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOrientation,
222 bool aDimmed ) const;
223
224 void Offset( const VECTOR2I& aOffset ) override;
225
226 void MoveTo( const VECTOR2I& aNewPosition ) override;
227
228 VECTOR2I GetPosition() const override { return m_position; }
229 void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; }
230
231 VECTOR2I GetPinRoot() const;
232
233 void MirrorHorizontal( const VECTOR2I& aCenter ) override;
234 void MirrorVertical( const VECTOR2I& aCenter ) override;
235 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
236
237 void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
238 const TRANSFORM& aTransform, bool aDimmed ) const override;
239
240 BITMAPS GetMenuImage() const override;
241
242 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
243
244 EDA_ITEM* Clone() const override;
245
246 void CalcEdit( const VECTOR2I& aPosition ) override;
247
256 static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
257
258protected:
263 void printPinSymbol( const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, int aOrientation,
264 bool aDimmed );
265
274 void printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, int aPinOrient,
275 int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed );
276
280 void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition,
281 int aOrientation, bool aDimmed );
282
283private:
293 int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
294
295protected:
296 VECTOR2I m_position; // Position of the pin.
297 int m_length; // Length of the pin.
298 int m_orientation; // Pin orientation (Up, Down, Left, Right)
299 GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
300 ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
301 int m_attributes; // Set bit 0 to indicate pin is invisible.
302 wxString m_name;
303 wxString m_number;
304 int m_numTextSize; // Pin num and Pin name sizes
306
307 std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
308
309 wxString m_operatingPoint; // No, LIB_PINs don't really have operating points.
310 // But we draw SCH_PINs through their LIB_PIN
311 // counterparts, so here we are....
312};
313
314
315#endif // CLASS_PIN_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:168
bool IsGlobalPower() const
Return whether this pin forms a global power connection: i.e., is part of a power symbol and of type ...
Definition: lib_pin.h:203
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:78
int m_attributes
Definition: lib_pin.h:301
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: lib_pin.cpp:1195
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1093
int GetLength() const
Definition: lib_pin.h:80
void Offset(const VECTOR2I &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1077
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:90
void SetPosition(const VECTOR2I &aPos) override
Definition: lib_pin.h:229
void PlotPinTexts(PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed) const
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:758
int GetOrientation() const
Definition: lib_pin.h:74
const BOX2I GetBoundingBox() const override
Definition: lib_pin.h:189
void SetName(const wxString &aName)
Definition: lib_pin.h:114
void MirrorVertical(const VECTOR2I &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:1106
int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:972
void SetNameTextSize(int aSize)
Definition: lib_pin.h:133
wxString m_name
Definition: lib_pin.h:302
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:91
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: lib_pin.cpp:1189
int m_nameTextSize
Definition: lib_pin.h:305
wxString GetShownNumber() const
Definition: lib_pin.h:123
LIB_PIN(LIB_SYMBOL *aParent)
Definition: lib_pin.cpp:97
int GetNumberTextSize() const
Definition: lib_pin.h:135
void printPinSymbol(const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, int aOrientation, bool aDimmed)
Print the pin symbol without text.
Definition: lib_pin.cpp:251
void SetVisible(bool aVisible)
Definition: lib_pin.h:104
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_pin.cpp:1164
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: lib_pin.cpp:1367
wxString GetShownName() const
Definition: lib_pin.cpp:175
int m_length
Definition: lib_pin.h:297
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:1119
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: lib_pin.cpp:1049
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:93
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1361
void MoveTo(const VECTOR2I &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1083
wxString GetClass() const override
Return the class name.
Definition: lib_pin.h:64
VECTOR2I m_position
Definition: lib_pin.h:296
void SetOperatingPoint(const wxString &aText)
Definition: lib_pin.h:172
int m_orientation
Definition: lib_pin.h:298
int m_numTextSize
Definition: lib_pin.h:304
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:299
VECTOR2I GetPosition() const override
Definition: lib_pin.h:228
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1428
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:138
~LIB_PIN()
Definition: lib_pin.h:62
const wxString & GetOperatingPoint() const
Definition: lib_pin.h:171
const wxString & GetNumber() const
Definition: lib_pin.h:122
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:98
std::map< wxString, ALT > m_alternates
Definition: lib_pin.h:307
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:77
bool IsVisible() const
Definition: lib_pin.h:103
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:124
void print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed) override
Print a pin, with or without the pin texts.
Definition: lib_pin.cpp:197
ALT GetAlt(const wxString &aAlt)
Definition: lib_pin.h:140
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:300
const wxString & GetName() const
Definition: lib_pin.h:112
void Plot(PLOTTER *aPlotter, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:1148
int PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition: lib_pin.cpp:932
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:69
wxString m_number
Definition: lib_pin.h:303
void SetLength(int aLength)
Definition: lib_pin.h:81
int GetNameTextSize() const
Definition: lib_pin.h:132
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:966
VECTOR2I GetPinRoot() const
Definition: lib_pin.cpp:184
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: lib_pin.cpp:144
int GetPenWidth() const override
Definition: lib_pin.cpp:169
void printPinElectricalTypeName(const RENDER_SETTINGS *aSettings, VECTOR2I &aPosition, int aOrientation, bool aDimmed)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:548
void PlotSymbol(PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOrientation, bool aDimmed) const
Definition: lib_pin.cpp:615
void SetOrientation(int aOrientation)
Definition: lib_pin.h:75
void SetNumberTextSize(int aSize)
Definition: lib_pin.h:136
wxString m_operatingPoint
Definition: lib_pin.h:309
void printPinTexts(const RENDER_SETTINGS *aSettings, VECTOR2I &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:375
Define a library symbol object.
Definition: lib_symbol.h:99
bool IsPower() const
Definition: lib_symbol.cpp:545
Base plotter engine class.
Definition: plotter.h:110
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47
#define _(s)
DrawPinOrient
The symbol library pin object orientations.
Definition: lib_pin.h:44
@ PIN_LEFT
Definition: lib_pin.h:46
@ PIN_RIGHT
Definition: lib_pin.h:45
@ PIN_UP
Definition: lib_pin.h:47
@ PIN_DOWN
Definition: lib_pin.h:48
#define PIN_INVISIBLE
Definition: lib_pin.h:38
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:240
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
GRAPHIC_PINSHAPE
Definition: pin_type.h:56
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:58
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:59
wxString m_Name
Definition: lib_pin.h:57