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@verizon.net>
6  * Copyright (C) 2004-2015 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 
30 #ifndef CLASS_PIN_H
31 #define CLASS_PIN_H
32 
33 class SCH_COMPONENT;
34 
35 #include <class_eda_rect.h>
36 #include <lib_draw_item.h>
37 
38 #include "pin_shape.h"
39 #include "pin_type.h"
40 
41 // Circle diameter drawn at the active end of pins:
42 #define TARGET_PIN_RADIUS 12
43 
44 // Pin visibility flag bit:
45 #define PIN_INVISIBLE 1 // Set makes pin invisible
46 
47 
52  PIN_RIGHT = 'R',
53  PIN_LEFT = 'L',
54  PIN_UP = 'U',
55  PIN_DOWN = 'D'
56 };
57 
60  PIN_DRAW_DANGLING = 2, // Draw this pin with a 'dangling' indicator
61  PIN_DANGLING_HIDDEN = 4, // Draw (only!) the dangling indicator if the pin is hidden
62  PIN_DRAW_ELECTRICAL_TYPE_NAME = 8 // Draw the pin electrical type name
63  // used only in component editor and component viewer
64 };
65 
66 
67 class LIB_PIN : public LIB_ITEM
68 {
70  int m_length;
73  int m_width;
76  wxString m_name;
77  long m_number;
78  int m_numTextSize;
82 
98  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
99  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
100  const TRANSFORM& aTransform ) override;
101 
102 public:
103  LIB_PIN( LIB_PART* aParent );
104 
105  // Do not create a copy constructor. The one generated by the compiler is adequate.
106 
107  ~LIB_PIN() { }
108 
109  wxString GetClass() const override
110  {
111  return wxT( "LIB_PIN" );
112  }
113 
114 #if defined(DEBUG)
115  void Show( int nestLevel, std::ostream& os ) const override;
116 #endif
117 
118  bool Save( OUTPUTFORMATTER& aFormatter ) override;
119 
120  bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ) override;
121 
122  bool HitTest( const wxPoint& aPosition ) const override;
123 
124  bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const override;
125 
126  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
127 
134  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList, SCH_COMPONENT* aComponent );
135 
136  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
137 
138  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
139  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
140 
146  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
147 
153  wxPoint PinEndPoint() const;
154 
162  int PinDrawOrient( const TRANSFORM& aTransform ) const;
163 
172  void PinStringNum( wxString& aStringBuffer ) const;
173 
174  long GetNumber() const { return m_number; }
175 
176  wxString GetNumberString() const { return PinStringNum( m_number ); }
177 
185  static wxString PinStringNum( long aPinNum );
186 
191  void SetPinNumFromString( wxString& aBuffer );
192 
193  wxString GetName() const { return m_name; }
194 
202  void SetName( const wxString& aName );
203 
212  void SetNameTextSize( int aSize );
213 
214  int GetNameTextSize() const { return m_nameTextSize; }
215 
223  void SetNumber( const wxString& aNumber );
224 
233  void SetNumberTextSize( int aSize );
234 
235  int GetNumberTextSize() const { return m_numTextSize; }
236 
237  int GetOrientation() const { return m_orientation; }
238 
246  void SetOrientation( int aOrientation );
247 
248  void Rotate() override;
249 
250  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
251 
259  void SetShape( GRAPHIC_PINSHAPE aShape );
260 
266  ELECTRICAL_PINTYPE GetType() const { return m_type; }
267 
274  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
275 
281  wxString const GetCanonicalElectricalTypeName() const
282  {
283  return GetCanonicalElectricalTypeName( m_type );
284  }
285 
290  wxString const GetElectricalTypeName() const
291  {
292  return GetText( m_type );
293  }
294 
303  void SetType( ELECTRICAL_PINTYPE aType );
304 
312  void SetLength( int aLength );
313 
314  int GetLength() { return m_length; }
315 
325  void SetPartNumber( int aPart );
326 
328  int GetPartNumber() const { return m_Unit; }
329 
339  void SetConversion( int aConversion );
340 
349  void SetVisible( bool aVisible );
350 
366  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
367 
373  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
374 
379  bool IsPowerConnection() const { return !IsVisible() && GetType() == PIN_POWER_IN; }
380 
381  int GetPenSize() const override;
382 
388  void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
389  int aOrientation, GR_DRAWMODE aDrawMode,
390  COLOR4D aColor = COLOR4D::UNSPECIFIED,
391  bool aDrawDangling = true,
392  bool aOnlyTarget = false );
393 
404  void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
405  int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
406  COLOR4D aColor, GR_DRAWMODE aDrawMode );
407 
413  void DrawPinElectricalTypeName( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
414  int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode );
415 
424  void PlotPinTexts( PLOTTER *aPlotter,
425  wxPoint& aPosition,
426  int aOrientation,
427  int aTextInside,
428  bool aDrawPinNum,
429  bool aDrawPinName,
430  int aWidth );
431 
432  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
433 
439  static wxArrayString GetOrientationNames();
440 
446  static const BITMAP_DEF* GetOrientationSymbols();
447 
455  static int GetOrientationCode( int aIndex );
456 
464  static int GetOrientationCodeIndex( int aCode );
465 
466  void SetOffset( const wxPoint& aOffset ) override;
467 
468  bool Inside( EDA_RECT& aRect ) const override;
469 
470  void Move( const wxPoint& aPosition ) override;
471 
472  wxPoint GetPosition() const override { return m_position; }
473 
480  void SetPinPosition( wxPoint aPosition );
481 
482  void MirrorHorizontal( const wxPoint& aCenter ) override;
483 
484  void MirrorVertical( const wxPoint& aCenter ) override;
485 
486  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
487 
488  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
489  const TRANSFORM& aTransform ) override;
490 
491  int GetWidth() const override { return m_width; }
492 
493  void SetWidth( int aWidth ) override;
494 
495  BITMAP_DEF GetMenuImage() const override;
496 
497  wxString GetSelectMenuText() const override;
498 
499  EDA_ITEM* Clone() const override;
500 
501 private:
507  void getMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
508 
509 
519  int compare( const LIB_ITEM& aOther ) const override;
520 };
521 
522 
523 #endif // CLASS_PIN_H
void SetNumberTextSize(int aSize)
Set the size of the pin number text.
Definition: lib_pin.cpp:231
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:109
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:2359
int compare(const LIB_ITEM &aOther) const override
Function compare provides the draw object specific comparison called by the == and < operators...
Definition: lib_pin.cpp:1931
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:81
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1925
wxString GetName() const
Definition: lib_pin.h:193
void DrawPinElectricalTypeName(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Function DrawPinElectricalTypeName draws the electrical type text of the pin (only for the footprint ...
Definition: lib_pin.cpp:1397
PNG memory record (file in memory).
Definition: bitmap_types.h:38
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:72
void SetOrientation(int aOrientation)
Set orientation on the pin.
Definition: lib_pin.cpp:256
Electrical pin type handling.
int m_numTextSize
Definition: lib_pin.h:80
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:2079
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:2269
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:2337
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:282
LibPinDrawFlags
Definition: lib_pin.h:58
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:281
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:290
void SetWidth(int aWidth) override
Function SetWidth sets the width of the draw item to aWidth.
Definition: lib_pin.cpp:2069
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:328
long GetNumber() const
Definition: lib_pin.h:174
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1955
int m_Unit
Unit identification for multiple parts per package.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
void SetLength(int aLength)
Set the pin length.
Definition: lib_pin.cpp:344
wxString m_name
Definition: lib_pin.h:76
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:2331
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo displays basic info (type, part and convert) about the current item in messa...
Definition: lib_pin.cpp:2117
Pin shape handling.
Definition: lib_pin.h:54
void EnableEditMode(bool aEnable, bool aEditPinByPin=false)
Enable or clear pin editing mode.
Definition: lib_pin.cpp:492
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPosition, int aOrientation, int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth)
Function PlotPinTexts plots the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1610
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:139
int GetNameTextSize() const
Definition: lib_pin.h:214
int GetOrientation() const
Definition: lib_pin.h:237
int m_length
Length of the pin.
Definition: lib_pin.h:70
int GetWidth() const override
Function GetWidth return the width of the draw item.
Definition: lib_pin.h:491
static int GetOrientationCodeIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:2289
int GetNumberTextSize() const
Definition: lib_pin.h:235
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
void MirrorVertical(const wxPoint &aCenter) override
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_pin.cpp:1991
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform) override
Draw a pin, with or without the pin texts.
Definition: lib_pin.cpp:905
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:428
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:214
int GetPenSize() const override
Function GetPenSize.
Definition: lib_pin.cpp:899
bool Load(LINE_READER &aLineReader, wxString &aErrorMsg) override
Definition: lib_pin.cpp:686
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:71
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
void SetType(ELECTRICAL_PINTYPE aType)
Set the electrical type of the pin.
Definition: lib_pin.cpp:311
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1459
~LIB_PIN()
Definition: lib_pin.h:107
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
#define PIN_INVISIBLE
Definition: lib_pin.h:45
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:266
bool Inside(EDA_RECT &aRect) const override
Function Inside tests if any part of the draw object is inside rectangle bounds of aRect...
Definition: lib_pin.cpp:1961
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: lib_pin.cpp:518
Class LIB_PART defines a library part object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:459
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:2303
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:373
void DrawPinTexts(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Function DrawPinTexts puts the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1179
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:144
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin edition.
Definition: lib_pin.cpp:371
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:472
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:75
Base plotter engine class.
Definition: plot_common.h:86
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:69
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:398
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:2052
wxPoint PinEndPoint() const
Function PinEndPoint.
Definition: lib_pin.cpp:1814
void SetName(const wxString &aName)
Set the pin name.
Definition: lib_pin.cpp:160
void SetNameTextSize(int aSize)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:189
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
void PinStringNum(wxString &aStringBuffer) const
Fill a string buffer with pin number.
Definition: lib_pin.cpp:1886
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:2343
Class EDA_RECT handles the component boundary box.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
void Move(const wxPoint &aPosition) override
Function Move moves a draw object to aPosition.
Definition: lib_pin.cpp:1969
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:74
void SetPinNumFromString(wxString &aBuffer)
Function SetPinNumFromString fill the pin number buffer with aBuffer.
Definition: lib_pin.cpp:1905
DrawPinOrient
The component library pin object orientations.
Definition: lib_pin.h:51
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:379
int m_width
Line width of the pin.
Definition: lib_pin.h:73
int GetLength()
Definition: lib_pin.h:314
void DrawPinSymbol(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, int aOrientation, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED, bool aDrawDangling=true, bool aOnlyTarget=false)
Function DrawPinSymbol Draw the pin symbol without text.
Definition: lib_pin.cpp:980
bool Save(OUTPUTFORMATTER &aFormatter) override
Function Save writes draw item object to aFormatter in component library "*.lib" format.
Definition: lib_pin.cpp:542
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:250
long m_number
Pin number defined as 4 ASCII characters like "12", "anod", "G6", or "12".
Definition: lib_pin.h:77
int PinDrawOrient(const TRANSFORM &aTransform) const
Function PinDrawOrient returns the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation and the matrix transform (rot, mirror) aTransform.
Definition: lib_pin.cpp:1841
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_pin.cpp:1979
wxString GetNumberString() const
Definition: lib_pin.h:176
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:2280
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39