KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <iostream>
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
41class LIB_PIN : public LIB_ITEM
42{
43public:
44 struct ALT
45 {
46 wxString m_Name;
47 GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin
48 ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin.
49 };
50
52
53 wxString GetClass() const override
54 {
55 return wxT( "LIB_PIN" );
56 }
57
58 static inline bool ClassOf( const EDA_ITEM* aItem )
59 {
60 return aItem && aItem->Type() == LIB_PIN_T;
61 }
62
63 wxString GetTypeName() const override
64 {
65 return _( "Pin" );
66 }
67
69 void SetOrientation( PIN_ORIENTATION aOrientation ) { m_orientation = aOrientation; }
70
71 GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
72 void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
73
74 int GetLength() const { return m_length; }
75 void SetLength( int aLength ) { m_length = aLength; }
76
82 void ChangeLength( int aLength );
83
84 ELECTRICAL_PINTYPE GetType() const { return m_type; }
85 void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; }
86
87 wxString const GetCanonicalElectricalTypeName() const
88 {
90 }
91
92 wxString const GetElectricalTypeName() const
93 {
95 }
96
97 bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
98 void SetVisible( bool aVisible )
99 {
100 if( aVisible )
101 m_attributes &= ~PIN_INVISIBLE;
102 else
104 }
105
106 const wxString& GetName() const { return m_name; }
107 wxString GetShownName() const;
108 void SetName( const wxString& aName )
109 {
110 m_name = aName;
111
112 // pin name string does not support spaces
113 m_name.Replace( wxT( " " ), wxT( "_" ) );
115 }
116
117 const wxString& GetNumber() const { return m_number; }
118 wxString GetShownNumber() const { return m_number; }
119 void SetNumber( const wxString& aNumber )
120 {
121 m_number = aNumber;
122
123 // pin number string does not support spaces
124 m_number.Replace( wxT( " " ), wxT( "_" ) );
126 }
127
128 int GetNameTextSize() const { return m_nameTextSize; }
129 void SetNameTextSize( int aSize )
130 {
131 m_nameTextSize = aSize;
133 }
134
135 int GetNumberTextSize() const { return m_numTextSize; }
136 void SetNumberTextSize( int aSize )
137 {
138 m_numTextSize = aSize;
140 }
141
142 std::map<wxString, ALT>& GetAlternates() { return m_alternates; }
143
144 ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; }
145
154 void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
155 const TRANSFORM& aTransform, bool aDimmed ) override;
156
163 PIN_ORIENTATION PinDrawOrient( const TRANSFORM& aTransform ) const;
164
165 LIB_PIN( LIB_SYMBOL* aParent );
166
167 LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber,
168 PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength,
169 int aNameTextSize, int aNumTextSize, int aConvert, const VECTOR2I& aPos, int aUnit );
170
171 // Do not create a copy constructor. The one generated by the compiler is adequate.
172
173 // No, LIB_PINs don't really have operating poinst. But we draw SCH_PINs through their LIB_PIN
174 // counterparts, so here we are....
175 const wxString& GetOperatingPoint() const { return m_operatingPoint; }
176 void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
177
178#if defined(DEBUG)
179 void Show( int nestLevel, std::ostream& os ) const override;
180#endif
181
182 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
183
184 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
185
186 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
187
188 const BOX2I ViewBBox() const override;
189
190 void ViewGetLayers( int aLayers[], int& aCount ) const override;
191
192 /* Cannot use a default parameter here as it will not be compatible with the virtual. */
193 const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, true ); }
194
199 const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
200 bool aIncludeElectricalType ) const;
201
207 bool IsGlobalPower() const
208 {
209 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
210 && ( !IsVisible() || (LIB_SYMBOL*) GetParent()->IsPower() );
211 }
212
213 int GetPenWidth() const override;
214
222 void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
223 int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const;
224
225 void PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation,
226 bool aDimmed ) const;
227
228 void Offset( const VECTOR2I& aOffset ) override;
229
230 void MoveTo( const VECTOR2I& aNewPosition ) override;
231
232 VECTOR2I GetPosition() const override { return m_position; }
233 void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; }
234
235 // For properties system
236 int GetX() const { return m_position.x; }
237 void SetX( int aX ) { m_position.x = aX; }
238 int GetY() const { return m_position.y; }
239 void SetY( int aY ) { m_position.y = aY; }
240
241 VECTOR2I GetPinRoot() const;
242
243 void MirrorHorizontal( const VECTOR2I& aCenter ) override;
244 void MirrorVertical( const VECTOR2I& aCenter ) override;
245 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
246
247 void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
248 const TRANSFORM& aTransform, bool aDimmed ) const override;
249
250 BITMAPS GetMenuImage() const override;
251
252 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
253 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const;
254
255 EDA_ITEM* Clone() const override;
256
257 void CalcEdit( const VECTOR2I& aPosition ) override;
258
267 static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
268
269 double Similarity( const LIB_ITEM& aItem ) const override;
270
271 bool operator==( const LIB_ITEM& aItem ) const override;
272 bool operator!=( const LIB_ITEM& aItem ) const { return !operator==( aItem ); }
273 bool operator<( const LIB_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) < 0; }
274 bool operator>( const LIB_PIN& aRhs ) const { return compare( aRhs, EQUALITY ) > 0; }
275
276protected:
277 wxString getItemDescription( ALT* aAlt ) const;
278
280 {
282 int m_FontSize = 0;
284 };
285
286 void validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
287 EXTENTS_CACHE* aCache ) const;
288
293 void printPinSymbol( const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos,
294 PIN_ORIENTATION aOrientation, bool aDimmed );
295
304 void printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos,
305 PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum,
306 bool aDrawPinName, bool aDimmed );
307
311 void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition,
312 PIN_ORIENTATION aOrientation, bool aDimmed );
313 std::ostream& operator<<( std::ostream& aStream );
314
315private:
325 int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
326
327protected:
328 VECTOR2I m_position; // Position of the pin.
329 int m_length; // Length of the pin.
330 PIN_ORIENTATION m_orientation; // Pin orientation (Up, Down, Left, Right)
331 GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
332 ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
333 int m_attributes; // Set bit 0 to indicate pin is invisible.
334 wxString m_name;
335 wxString m_number;
336 int m_numTextSize; // Pin num and Pin name sizes
338
339 std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
340
341 wxString m_operatingPoint; // No, LIB_PINs don't really have simulation
342 // operating points. But we draw SCH_PINs through
343 // their LIB_PIN counterparts, so here we are....
344
347};
348
349
350#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
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
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:68
@ EQUALITY
Definition: lib_item.h:96
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:209
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:207
void printPinElectricalTypeName(const RENDER_SETTINGS *aSettings, VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:557
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:72
int m_attributes
Definition: lib_pin.h:333
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:1221
void MirrorHorizontal(const VECTOR2I &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1116
int GetLength() const
Definition: lib_pin.h:74
void Offset(const VECTOR2I &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1104
bool operator<(const LIB_PIN &aRhs) const
Definition: lib_pin.h:273
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:84
void SetPosition(const VECTOR2I &aPos) override
Definition: lib_pin.h:233
const BOX2I GetBoundingBox() const override
Definition: lib_pin.h:193
void SetName(const wxString &aName)
Definition: lib_pin.h:108
void MirrorVertical(const VECTOR2I &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:1129
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:999
int GetX() const
Definition: lib_pin.h:236
void SetNameTextSize(int aSize)
Definition: lib_pin.h:129
wxString m_name
Definition: lib_pin.h:334
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition: lib_pin.cpp:1235
void PlotPinTexts(PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION 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:768
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:85
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: lib_pin.cpp:1215
PIN_ORIENTATION GetOrientation() const
Definition: lib_pin.h:68
int m_nameTextSize
Definition: lib_pin.h:337
wxString getItemDescription(ALT *aAlt) const
Definition: lib_pin.cpp:1411
std::ostream & operator<<(std::ostream &aStream)
Definition: lib_pin.cpp:1578
void SetY(int aY)
Definition: lib_pin.h:239
wxString GetShownNumber() const
Definition: lib_pin.h:118
int GetNumberTextSize() const
Definition: lib_pin.h:135
void SetVisible(bool aVisible)
Definition: lib_pin.h:98
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:1187
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: lib_pin.cpp:1405
wxString GetShownName() const
Definition: lib_pin.cpp:176
int m_length
Definition: lib_pin.h:329
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:1142
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: lib_pin.cpp:1076
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1393
void SetX(int aX)
Definition: lib_pin.h:237
void MoveTo(const VECTOR2I &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1110
wxString GetClass() const override
Return the class name.
Definition: lib_pin.h:53
VECTOR2I m_position
Definition: lib_pin.h:328
bool operator==(const LIB_ITEM &aItem) const override
Test LIB_ITEM objects for equivalence.
Definition: lib_pin.cpp:1461
void SetOperatingPoint(const wxString &aText)
Definition: lib_pin.h:176
int m_numTextSize
Definition: lib_pin.h:336
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:331
static bool ClassOf(const EDA_ITEM *aItem)
Definition: lib_pin.h:58
EXTENTS_CACHE m_nameExtentsCache
Definition: lib_pin.h:346
VECTOR2I GetPosition() const override
Definition: lib_pin.h:232
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1608
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:142
~LIB_PIN()
Definition: lib_pin.h:51
const wxString & GetOperatingPoint() const
Definition: lib_pin.h:175
bool operator!=(const LIB_ITEM &aItem) const
Definition: lib_pin.h:272
const wxString & GetNumber() const
Definition: lib_pin.h:117
PIN_ORIENTATION 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:959
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:92
std::map< wxString, ALT > m_alternates
Definition: lib_pin.h:339
int GetY() const
Definition: lib_pin.h:238
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: lib_pin.h:69
EXTENTS_CACHE m_numExtentsCache
Definition: lib_pin.h:345
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:71
bool IsVisible() const
Definition: lib_pin.h:97
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:119
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:198
void printPinSymbol(const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, PIN_ORIENTATION aOrientation, bool aDimmed)
Print the pin symbol without text.
Definition: lib_pin.cpp:252
PIN_ORIENTATION m_orientation
Definition: lib_pin.h:330
ALT GetAlt(const wxString &aAlt)
Definition: lib_pin.h:144
void printPinTexts(const RENDER_SETTINGS *aSettings, VECTOR2I &aPinPos, PIN_ORIENTATION 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:377
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:332
const wxString & GetName() const
Definition: lib_pin.h:106
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:1171
double Similarity(const LIB_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: lib_pin.cpp:1529
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:63
wxString m_number
Definition: lib_pin.h:335
void SetLength(int aLength)
Definition: lib_pin.h:75
void PlotSymbol(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition: lib_pin.cpp:624
int GetNameTextSize() const
Definition: lib_pin.h:128
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:993
VECTOR2I GetPinRoot() const
Definition: lib_pin.cpp:185
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:145
bool operator>(const LIB_PIN &aRhs) const
Definition: lib_pin.h:274
int GetPenWidth() const override
Definition: lib_pin.cpp:170
void SetNumberTextSize(int aSize)
Definition: lib_pin.h:136
wxString m_operatingPoint
Definition: lib_pin.h:341
Define a library symbol object.
Definition: lib_symbol.h:99
bool IsPower() const
Definition: lib_symbol.cpp:704
Base plotter engine class.
Definition: plotter.h:104
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
#define _(s)
#define PIN_INVISIBLE
Definition: lib_pin.h:38
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:196
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:75
GRAPHIC_PINSHAPE
Definition: pin_type.h:56
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:47
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:48
wxString m_Name
Definition: lib_pin.h:46
KIFONT::FONT * m_Font
Definition: lib_pin.h:281
@ LIB_PIN_T
Definition: typeinfo.h:206
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588