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 <stambaughw@gmail.com>
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 <eda_rect.h>
31 #include <lib_item.h>
32 #include <pin_type.h>
33 #include <lib_symbol.h>
34 
35 // Circle diameter drawn at the active end of pins:
36 #define TARGET_PIN_RADIUS Mils2iu( 15 )
37 
38 // Pin visibility flag bit:
39 #define PIN_INVISIBLE 1 // Set makes pin invisible
40 
41 
46  PIN_RIGHT = 'R',
47  PIN_LEFT = 'L',
48  PIN_UP = 'U',
49  PIN_DOWN = 'D'
50 };
51 
52 
53 class LIB_PIN : public LIB_ITEM
54 {
55 public:
56  struct ALT
57  {
58  wxString m_Name;
59  GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin
60  ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin.
61  };
62 
63  ~LIB_PIN() { }
64 
65  wxString GetClass() const override
66  {
67  return wxT( "LIB_PIN" );
68  }
69 
70  wxString GetTypeName() const override
71  {
72  return _( "Pin" );
73  }
74 
75  int GetOrientation() const { return m_orientation; }
76  void SetOrientation( int aOrientation ) { m_orientation = aOrientation; }
77 
78  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
79  void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
80 
81  int GetLength() const { return m_length; }
82  void SetLength( int aLength ) { m_length = 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 )
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( "_" ) );
114  }
115 
116  const wxString& GetNumber() const { return m_number; }
117  wxString GetShownNumber() const { return m_number; }
118  void SetNumber( const wxString& aNumber )
119  {
120  m_number = aNumber;
121 
122  // pin number string does not support spaces
123  m_number.Replace( wxT( " " ), wxT( "_" ) );
124  }
125 
126  int GetNameTextSize() const { return m_nameTextSize; }
127  void SetNameTextSize( int aSize ) { m_nameTextSize = aSize; }
128 
129  int GetNumberTextSize() const { return m_numTextSize; }
130  void SetNumberTextSize( int aSize ) { m_numTextSize = aSize; }
131 
132  std::map<wxString, ALT>& GetAlternates() { return m_alternates; }
133 
134  ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; }
135 
144  void print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
145  const TRANSFORM& aTransform ) override;
146 
153  int PinDrawOrient( const TRANSFORM& aTransform ) const;
154 
155  LIB_PIN( LIB_SYMBOL* aParent );
156 
157  LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber, int aOrientation,
158  ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize, int aNumTextSize,
159  int aConvert, const wxPoint& aPos, int aUnit );
160 
161  // Do not create a copy constructor. The one generated by the compiler is adequate.
162 
163 #if defined(DEBUG)
164  void Show( int nestLevel, std::ostream& os ) const override;
165 #endif
166 
167  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
168 
169  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
170 
171  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
172 
173  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
174  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
175 
180  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly = false ) const;
181 
186  bool IsPowerConnection() const
187  {
189  && ( !IsVisible() || (LIB_SYMBOL*) GetParent()->IsPower() );
190  }
191 
192  int GetPenWidth() const override;
193 
201  void PlotPinTexts( PLOTTER *aPlotter, const wxPoint& aPinPos, int aPinOrient,
202  int aTextInside, bool aDrawPinNum, bool aDrawPinName ) const;
203 
204  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation ) const;
205 
206  void Offset( const wxPoint& aOffset ) override;
207 
208  void MoveTo( const wxPoint& aNewPosition ) override;
209 
210  wxPoint GetPosition() const override { return m_position; }
211  void SetPosition( const wxPoint& aPos ) override { m_position = aPos; }
212 
213  void MirrorHorizontal( const wxPoint& aCenter ) override;
214  void MirrorVertical( const wxPoint& aCenter ) override;
215  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
216 
217  void Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
218  const TRANSFORM& aTransform ) const override;
219 
220  // Get/SetWidth() not used for pins. Use GetPenWidth() for drawing.
221  int GetWidth() const override { return 1; }
222  void SetWidth( int aWidth ) override { };
223 
224  BITMAPS GetMenuImage() const override;
225 
226  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
227 
228  EDA_ITEM* Clone() const override;
229 
230  void CalcEdit( const wxPoint& aPosition ) override;
231 
240  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
241 
242 protected:
247  void printPinSymbol( const RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrientation );
248 
257  void printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos, int aPinOrient,
258  int aTextInside, bool aDrawPinNum, bool aDrawPinName );
259 
263  void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, wxPoint& aPosition,
264  int aOrientation );
265 
266 private:
276  int compare( const LIB_ITEM& aOther,
277  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
278 
279 protected:
280  wxPoint m_position; // Position of the pin.
281  int m_length; // Length of the pin.
282  int m_orientation; // Pin orientation (Up, Down, Left, Right)
283  GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
284  ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
285  int m_attributes; // Set bit 0 to indicate pin is invisible.
286  wxString m_name;
287  wxString m_number;
288  int m_numTextSize; // Pin num and Pin name sizes
290 
291  std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
292 };
293 
294 
295 #endif // CLASS_PIN_H
void SetNumberTextSize(int aSize)
Definition: lib_pin.h:130
wxString GetClass() const override
Return the class name.
Definition: lib_pin.h:65
power input (GND, VCC for ICs). Must be connected to a power output.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: lib_pin.cpp:1177
int m_nameTextSize
Definition: lib_pin.h:289
wxString GetShownNumber() const
Definition: lib_pin.h:117
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:852
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:978
void Plot(PLOTTER *aPlotter, const wxPoint &aPffset, bool aFill, const TRANSFORM &aTransform) const override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:1007
void PlotPinTexts(PLOTTER *aPlotter, const wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName) const
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:666
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:283
void SetOrientation(int aOrientation)
Definition: lib_pin.h:76
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void MoveTo(const wxPoint &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:942
int m_numTextSize
Definition: lib_pin.h:288
int GetOrientation() const
Definition: lib_pin.h:75
void printPinTexts(const RENDER_SETTINGS *aSettings, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:328
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:237
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:79
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:78
LIB_PIN(LIB_SYMBOL *aParent)
Definition: lib_pin.cpp:94
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation) const
Definition: lib_pin.cpp:537
void SetWidth(int aWidth) override
Definition: lib_pin.h:222
void SetLength(int aLength)
Definition: lib_pin.h:82
wxString m_name
Definition: lib_pin.h:286
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: lib_pin.cpp:141
bool IsPower() const
Definition: lib_symbol.cpp:409
ALT GetAlt(const wxString &aAlt)
Definition: lib_pin.h:134
Definition: lib_pin.h:48
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:174
GRAPHIC_PINSHAPE
Definition: pin_type.h:55
The base class for create windows for drawing purpose.
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:818
void SetPosition(const wxPoint &aPos) override
Definition: lib_pin.h:211
int m_length
Definition: lib_pin.h:281
int GetWidth() const override
Definition: lib_pin.h:221
Define a library symbol object.
Definition: lib_symbol.h:96
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:60
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
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:186
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:965
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:118
int m_orientation
Definition: lib_pin.h:282
void printPinSymbol(const RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:217
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:85
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:287
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:92
~LIB_PIN()
Definition: lib_pin.h:63
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:81
const wxString & GetName() const
Definition: lib_pin.h:106
#define PIN_INVISIBLE
Definition: lib_pin.h:39
wxString m_Name
Definition: lib_pin.h:58
void SetVisible(bool aVisible)
Definition: lib_pin.h:98
#define _(s)
int GetPenWidth() const override
Definition: lib_pin.cpp:166
bool IsVisible() const
Definition: lib_pin.h:97
int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:858
int GetNameTextSize() const
Definition: lib_pin.h:126
wxString GetShownName() const
Definition: lib_pin.cpp:172
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1171
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:1022
void CalcEdit(const wxPoint &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1210
wxPoint GetPosition() const override
Definition: lib_pin.h:210
int m_attributes
Definition: lib_pin.h:285
EDA_UNITS
Definition: eda_units.h:38
const wxString & GetNumber() const
Definition: lib_pin.h:116
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:84
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:159
Base plotter engine class.
Definition: plotter.h:121
std::map< wxString, ALT > m_alternates
Definition: lib_pin.h:291
wxPoint m_position
Definition: lib_pin.h:280
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:132
int GetNumberTextSize() const
Definition: lib_pin.h:129
void SetName(const wxString &aName)
Definition: lib_pin.h:108
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void SetNameTextSize(int aSize)
Definition: lib_pin.h:127
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:35
int GetLength() const
Definition: lib_pin.h:81
void printPinElectricalTypeName(const RENDER_SETTINGS *aSettings, wxPoint &aPosition, int aOrientation)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:484
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:284
DrawPinOrient
The symbol library pin object orientations.
Definition: lib_pin.h:45
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:70
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:936
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:59
void print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print a pin, with or without the pin texts.
Definition: lib_pin.cpp:181
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:952