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  wxString m_number;
80 
96  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
97  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
98  const TRANSFORM& aTransform ) override;
99 
100 public:
101  LIB_PIN( LIB_PART* aParent );
102 
103  // Do not create a copy constructor. The one generated by the compiler is adequate.
104 
105  ~LIB_PIN() { }
106 
107  wxString GetClass() const override
108  {
109  return wxT( "LIB_PIN" );
110  }
111 
112 #if defined(DEBUG)
113  void Show( int nestLevel, std::ostream& os ) const override;
114 #endif
115 
116  bool Save( OUTPUTFORMATTER& aFormatter ) override;
117 
118  bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ) override;
119 
120  bool HitTest( const wxPoint& aPosition ) const override;
121 
122  bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const override;
123 
124  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
125 
132  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList, SCH_COMPONENT* aComponent );
133 
134  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
135 
136  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
137  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
138 
144  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
145 
151  wxPoint PinEndPoint() const;
152 
160  int PinDrawOrient( const TRANSFORM& aTransform ) const;
161 
162  const wxString& GetName() const
163  {
164  return m_name;
165  }
166 
174  void SetName( const wxString& aName );
175 
184  void SetNameTextSize( int aSize );
185 
186  int GetNameTextSize() const { return m_nameTextSize; }
187 
188  const wxString& GetNumber() const
189  {
190  return m_number;
191  }
192 
200  void SetNumber( const wxString& aNumber )
201  {
202  m_number = aNumber;
203  }
204 
213  void SetNumberTextSize( int aSize );
214 
215  int GetNumberTextSize() const { return m_numTextSize; }
216 
217  int GetOrientation() const { return m_orientation; }
218 
226  void SetOrientation( int aOrientation );
227 
228  void Rotate() override;
229 
230  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
231 
239  void SetShape( GRAPHIC_PINSHAPE aShape );
240 
246  ELECTRICAL_PINTYPE GetType() const { return m_type; }
247 
254  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
255 
261  wxString const GetCanonicalElectricalTypeName() const
262  {
263  return GetCanonicalElectricalTypeName( m_type );
264  }
265 
270  wxString const GetElectricalTypeName() const
271  {
272  return GetText( m_type );
273  }
274 
283  void SetType( ELECTRICAL_PINTYPE aType );
284 
292  void SetLength( int aLength );
293 
294  int GetLength() { return m_length; }
295 
305  void SetPartNumber( int aPart );
306 
308  int GetPartNumber() const { return m_Unit; }
309 
319  void SetConversion( int aConversion );
320 
329  void SetVisible( bool aVisible );
330 
346  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
347 
353  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
354 
359  bool IsPowerConnection() const { return !IsVisible() && GetType() == PIN_POWER_IN; }
360 
361  int GetPenSize() const override;
362 
368  void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
369  int aOrientation, GR_DRAWMODE aDrawMode,
370  COLOR4D aColor = COLOR4D::UNSPECIFIED,
371  bool aDrawDangling = true,
372  bool aOnlyTarget = false );
373 
384  void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
385  int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
386  COLOR4D aColor, GR_DRAWMODE aDrawMode );
387 
393  void DrawPinElectricalTypeName( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
394  int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode );
395 
404  void PlotPinTexts( PLOTTER *aPlotter,
405  wxPoint& aPosition,
406  int aOrientation,
407  int aTextInside,
408  bool aDrawPinNum,
409  bool aDrawPinName,
410  int aWidth );
411 
412  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
413 
419  static wxArrayString GetOrientationNames();
420 
426  static const BITMAP_DEF* GetOrientationSymbols();
427 
435  static int GetOrientationCode( int aIndex );
436 
444  static int GetOrientationCodeIndex( int aCode );
445 
446  void SetOffset( const wxPoint& aOffset ) override;
447 
448  bool Inside( EDA_RECT& aRect ) const override;
449 
450  void Move( const wxPoint& aPosition ) override;
451 
452  wxPoint GetPosition() const override { return m_position; }
453 
460  void SetPinPosition( wxPoint aPosition );
461 
462  void MirrorHorizontal( const wxPoint& aCenter ) override;
463 
464  void MirrorVertical( const wxPoint& aCenter ) override;
465 
466  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
467 
468  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
469  const TRANSFORM& aTransform ) override;
470 
471  int GetWidth() const override { return m_width; }
472 
473  void SetWidth( int aWidth ) override;
474 
475  BITMAP_DEF GetMenuImage() const override;
476 
477  wxString GetSelectMenuText() const override;
478 
479  EDA_ITEM* Clone() const override;
480 
481 private:
487  void getMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
488 
489 
499  int compare( const LIB_ITEM& aOther ) const override;
500 };
501 
502 
503 #endif // CLASS_PIN_H
void SetNumberTextSize(int aSize)
Set the size of the pin number text.
Definition: lib_pin.cpp:213
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:107
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:2282
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:1861
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:79
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:1855
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:1370
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:238
Electrical pin type handling.
int m_numTextSize
Definition: lib_pin.h:78
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:2009
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:2194
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:2262
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:264
LibPinDrawFlags
Definition: lib_pin.h:58
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:261
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:270
void SetWidth(int aWidth) override
Function SetWidth sets the width of the draw item to aWidth.
Definition: lib_pin.cpp:1999
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:308
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1885
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:326
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:2256
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:2042
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:474
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:1583
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:137
int GetNameTextSize() const
Definition: lib_pin.h:186
int GetOrientation() const
Definition: lib_pin.h:217
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:471
static int GetOrientationCodeIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:2214
int GetNumberTextSize() const
Definition: lib_pin.h:215
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
const wxString & GetNumber() const
Definition: lib_pin.h:188
void MirrorVertical(const wxPoint &aCenter) override
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_pin.cpp:1921
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:882
const wxString & GetName() const
Definition: lib_pin.h:162
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:410
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.h:200
int GetPenSize() const override
Function GetPenSize.
Definition: lib_pin.cpp:876
bool Load(LINE_READER &aLineReader, wxString &aErrorMsg) override
Definition: lib_pin.cpp:663
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:293
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:77
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1432
~LIB_PIN()
Definition: lib_pin.h:105
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:246
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:1891
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:500
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:441
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:2228
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:353
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:1156
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:353
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:452
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:380
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:1982
wxPoint PinEndPoint() const
Function PinEndPoint.
Definition: lib_pin.cpp:1783
void SetName(const wxString &aName)
Set the pin name.
Definition: lib_pin.cpp:159
void SetNameTextSize(int aSize)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:188
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:2268
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:1899
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:74
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:359
int m_width
Line width of the pin.
Definition: lib_pin.h:73
int GetLength()
Definition: lib_pin.h:294
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:957
bool Save(OUTPUTFORMATTER &aFormatter) override
Function Save writes draw item object to aFormatter in component library "*.lib" format.
Definition: lib_pin.cpp:524
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:230
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:1810
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_pin.cpp:1909
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:2205
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39