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-2021 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#if defined(DEBUG)
170 void Show( int nestLevel, std::ostream& os ) const override;
171#endif
172
173 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
174
175 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
176
177 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
178
179 const BOX2I ViewBBox() const override;
180
181 void ViewGetLayers( int aLayers[], int& aCount ) const override;
182
183 /* Cannot use a default parameter here as it will not be compatible with the virtual. */
184 const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); }
185
190 const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
191 bool aIncludeElectricalType ) const;
192
197 bool IsPowerConnection() const
198 {
200 && ( !IsVisible() || (LIB_SYMBOL*) GetParent()->IsPower() );
201 }
202
203 int GetPenWidth() const override;
204
212 void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPinOrient, int aTextInside,
213 bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const;
214
215 void PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOrientation,
216 bool aDimmed ) const;
217
218 void Offset( const VECTOR2I& aOffset ) override;
219
220 void MoveTo( const VECTOR2I& aNewPosition ) override;
221
222 VECTOR2I GetPosition() const override { return m_position; }
223 void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; }
224
225 VECTOR2I GetPinRoot() const;
226
227 void MirrorHorizontal( const VECTOR2I& aCenter ) override;
228 void MirrorVertical( const VECTOR2I& aCenter ) override;
229 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
230
231 void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
232 const TRANSFORM& aTransform, bool aDimmed ) const override;
233
234 BITMAPS GetMenuImage() const override;
235
236 wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
237
238 EDA_ITEM* Clone() const override;
239
240 void CalcEdit( const VECTOR2I& aPosition ) override;
241
250 static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
251
252protected:
257 void printPinSymbol( const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, int aOrientation,
258 bool aDimmed );
259
268 void printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, int aPinOrient,
269 int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed );
270
274 void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition,
275 int aOrientation, bool aDimmed );
276
277private:
287 int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
288
289protected:
290 VECTOR2I m_position; // Position of the pin.
291 int m_length; // Length of the pin.
292 int m_orientation; // Pin orientation (Up, Down, Left, Right)
293 GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
294 ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
295 int m_attributes; // Set bit 0 to indicate pin is invisible.
296 wxString m_name;
297 wxString m_number;
298 int m_numTextSize; // Pin num and Pin name sizes
300
301 std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
302};
303
304
305#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
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:78
int m_attributes
Definition: lib_pin.h:295
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:1172
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1070
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:1054
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:90
void SetPosition(const VECTOR2I &aPos) override
Definition: lib_pin.h:223
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:744
int GetOrientation() const
Definition: lib_pin.h:74
const BOX2I GetBoundingBox() const override
Definition: lib_pin.h:184
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:1083
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:949
void SetNameTextSize(int aSize)
Definition: lib_pin.h:133
wxString m_name
Definition: lib_pin.h:296
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:1166
int m_nameTextSize
Definition: lib_pin.h:299
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:248
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:1141
wxString GetShownName() const
Definition: lib_pin.cpp:175
int m_length
Definition: lib_pin.h:291
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:1096
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: lib_pin.cpp:1026
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:1319
void MoveTo(const VECTOR2I &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1060
wxString GetClass() const override
Return the class name.
Definition: lib_pin.h:64
VECTOR2I m_position
Definition: lib_pin.h:290
int m_orientation
Definition: lib_pin.h:292
int m_numTextSize
Definition: lib_pin.h:298
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:293
VECTOR2I GetPosition() const override
Definition: lib_pin.h:222
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: lib_pin.cpp:1325
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1379
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:138
~LIB_PIN()
Definition: lib_pin.h:62
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:301
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:294
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:1125
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:909
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:297
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:943
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:540
void PlotSymbol(PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOrientation, bool aDimmed) const
Definition: lib_pin.cpp:604
void SetOrientation(int aOrientation)
Definition: lib_pin.h:75
void SetNumberTextSize(int aSize)
Definition: lib_pin.h:136
bool IsPowerConnection() const
Return whether this pin forms an implicit power connection: i.e., is hidden and of type POWER_IN.
Definition: lib_pin.h:197
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:369
Define a library symbol object.
Definition: lib_symbol.h:98
bool IsPower() const
Definition: lib_symbol.cpp:552
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