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-2020 KiCad Developers, see change_log.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 class SCH_COMPONENT;
31 
32 #include <eda_rect.h>
33 #include <lib_item.h>
34 
35 #include "pin_shape.h"
36 #include "pin_type.h"
37 #include "class_libentry.h"
38 
40 #define DEFAULT_PIN_NAME_OFFSET 40
41 
42 // Circle diameter drawn at the active end of pins:
43 #define TARGET_PIN_RADIUS Mils2iu( 15 )
44 
45 // Pin visibility flag bit:
46 #define PIN_INVISIBLE 1 // Set makes pin invisible
47 
48 
53  PIN_RIGHT = 'R',
54  PIN_LEFT = 'L',
55  PIN_UP = 'U',
56  PIN_DOWN = 'D'
57 };
58 
59 
60 class LIB_PIN : public LIB_ITEM
61 {
62 protected:
63  wxPoint m_position; // Position of the pin.
64  int m_length; // Length of the pin.
65  int m_orientation; // Pin orientation (Up, Down, Left, Right)
66  GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
67  ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
68  int m_attributes; // Set bit 0 to indicate pin is invisible.
69  wxString m_name;
70  wxString m_number;
71  int m_numTextSize; // Pin num and Pin name sizes
73 
74 protected:
79  void printPinSymbol( RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrientation );
80 
89  void printPinTexts( RENDER_SETTINGS* aSettings, wxPoint& aPosition, int aOrientation,
90  int TextInside, bool DrawPinNum, bool DrawPinName );
91 
95  void printPinElectricalTypeName( RENDER_SETTINGS* aSettings, wxPoint& aPosition,
96  int aOrientation );
97 
98 public:
104  static wxArrayString GetOrientationNames();
105 
111  static const BITMAP_DEF* GetOrientationSymbols();
112 
120  static int GetOrientationCode( int aIndex );
121 
129  static int GetOrientationIndex( int aCode );
130 
137  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
138 
139 public:
140  ~LIB_PIN() { }
141 
142  wxString GetClass() const override
143  {
144  return wxT( "LIB_PIN" );
145  }
146 
147  wxString GetTypeName() override
148  {
149  return _( "Pin" );
150  }
151 
152  int GetOrientation() const { return m_orientation; }
153  void SetOrientation( int aOrientation ) { m_orientation = aOrientation; }
154 
155  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
156  void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
157 
158  int GetLength() const { return m_length; }
159  void SetLength( int aLength ) { m_length = aLength; }
160 
161  ELECTRICAL_PINTYPE GetType() const { return m_type; }
162  void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; }
163 
164  wxString const GetCanonicalElectricalTypeName() const
165  {
167  }
168 
169  wxString const GetElectricalTypeName() const
170  {
172  }
173 
174  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
175  void SetVisible( bool aVisible )
176  {
177  if( aVisible )
179  else
181  }
182 
183  const wxString& GetName() const { return m_name; }
184  void SetName( const wxString& aName )
185  {
186  m_name = aName;
187 
188  // pin name string does not support spaces
189  m_name.Replace( wxT( " " ), wxT( "_" ) );
190  }
191 
192  const wxString& GetNumber() const { return m_number; }
193  void SetNumber( const wxString& aNumber )
194  {
195  m_number = aNumber;
196 
197  // pin number string does not support spaces
198  m_number.Replace( wxT( " " ), wxT( "_" ) );
199  }
200 
201  int GetNameTextSize() const { return m_nameTextSize; }
202  void SetNameTextSize( int aSize ) { m_nameTextSize = aSize; }
203 
204  int GetNumberTextSize() const { return m_numTextSize; }
205  void SetNumberTextSize( int aSize ) { m_numTextSize = aSize; }
206 
207  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles, bool aShowName, bool aShowNum,
208  int aNameTextOffset ) const;
217  void print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
218  const TRANSFORM& aTransform ) override;
219 
226  int PinDrawOrient( const TRANSFORM& aTransform ) const;
227 
228  LIB_PIN( LIB_PART* aParent );
229 
230  // Do not create a copy constructor. The one generated by the compiler is adequate.
231 
232 #if defined(DEBUG)
233  void Show( int nestLevel, std::ostream& os ) const override;
234 #endif
235 
236  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
237 
238  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
239 
240  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
241 
248  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList,
249  SCH_COMPONENT* aComponent );
250 
251  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
252  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
253 
258  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly = false ) const;
259 
264  bool IsPowerConnection() const
265  {
267  && ( !IsVisible() || (LIB_PART*) GetParent()->IsPower() );
268  }
269 
270  int GetPenWidth() const override;
271 
279  void PlotPinTexts( PLOTTER *aPlotter, wxPoint& aPosition, int aOrientation,
280  int aTextInside, bool aDrawPinNum, bool aDrawPinName );
281 
282  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
283 
284  void Offset( const wxPoint& aOffset ) override;
285 
286  void MoveTo( const wxPoint& aPosition ) override;
287 
288  wxPoint GetPosition() const override { return m_position; }
289  void SetPosition( const wxPoint& aPos ) { m_position = aPos; }
290 
291  void MirrorHorizontal( const wxPoint& aCenter ) override;
292  void MirrorVertical( const wxPoint& aCenter ) override;
293  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
294 
295  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
296  const TRANSFORM& aTransform ) override;
297 
298  // Get/SetWidth() not used for pins. Use GetPenWidth() for drawing.
299  int GetWidth() const override { return 1; }
300  void SetWidth( int aWidth ) override { };
301 
302  BITMAP_DEF GetMenuImage() const override;
303 
304  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
305 
306  EDA_ITEM* Clone() const override;
307 
308  void CalcEdit( const wxPoint& aPosition ) override;
309 
310 private:
316  void getMsgPanelInfoBase( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
317 
318 
328  int compare( const LIB_ITEM& aOther,
329  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
330 };
331 
332 
333 #endif // CLASS_PIN_H
void SetNumberTextSize(int aSize)
Definition: lib_pin.h:205
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:142
EDA_UNITS
Definition: common.h:198
void printPinElectricalTypeName(RENDER_SETTINGS *aSettings, wxPoint &aPosition, int aOrientation)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:499
power input (GND, VCC for ICs). Must be connected to a power output.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1286
int m_nameTextSize
Definition: lib_pin.h:72
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:899
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:999
PNG memory record (file in memory).
Definition: bitmap_def.h:29
void printPinTexts(RENDER_SETTINGS *aSettings, wxPoint &aPosition, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:357
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:66
void SetOrientation(int aOrientation)
Definition: lib_pin.h:153
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Electrical pin type handling.
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1260
int m_numTextSize
Definition: lib_pin.h:71
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1240
int GetOrientation() const
Definition: lib_pin.h:152
LIB_PART * GetParent() const
Definition: lib_item.h:182
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1280
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:59
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:156
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:155
void getMsgPanelInfoBase(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1043
void printPinSymbol(RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:248
void SetWidth(int aWidth) override
Definition: lib_pin.h:300
void SetLength(int aLength)
Definition: lib_pin.h:159
wxString m_name
Definition: lib_pin.h:69
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: lib_pin.cpp:189
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1274
Pin shape handling.
Definition: lib_pin.h:55
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:252
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:865
int m_length
Definition: lib_pin.h:64
int GetWidth() const override
Definition: lib_pin.h:299
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPosition, int aOrientation, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:679
The base class for drawable items used by schematic library components.
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:264
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:986
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:193
int m_orientation
Definition: lib_pin.h:65
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:162
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:70
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:551
void SetPosition(const wxPoint &aPos)
Definition: lib_pin.h:289
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:169
~LIB_PIN()
Definition: lib_pin.h:140
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:116
const wxString & GetName() const
Definition: lib_pin.h:183
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Define a library symbol object.
void SetVisible(bool aVisible)
Definition: lib_pin.h:175
int GetPenWidth() const override
Definition: lib_pin.cpp:214
bool IsVisible() const
Definition: lib_pin.h:174
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:905
int GetNameTextSize() const
Definition: lib_pin.h:201
void print(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:220
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.
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1308
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:161
wxPoint GetPosition() const override
Definition: lib_pin.h:288
int m_attributes
Definition: lib_pin.h:68
const wxString & GetNumber() const
Definition: lib_pin.h:192
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:161
Base plotter engine class.
Definition: plotter.h:114
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:963
wxPoint m_position
Definition: lib_pin.h:63
int GetNumberTextSize() const
Definition: lib_pin.h:204
bool IsPower() const
void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:1028
void SetName(const wxString &aName)
Definition: lib_pin.h:184
void SetNameTextSize(int aSize)
Definition: lib_pin.h:202
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
int GetLength() const
Definition: lib_pin.h:158
#define _(s)
Definition: 3d_actions.cpp:33
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Schematic symbol object.
Definition: sch_component.h:88
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:67
DrawPinOrient
The component library pin object orientations.
Definition: lib_pin.h:52
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:164
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:957
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:147
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:973
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1251