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 #include "class_libentry.h"
41 
42 // Circle diameter drawn at the active end of pins:
43 #define TARGET_PIN_RADIUS 12
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 
61  PIN_DRAW_DANGLING = 2, // Draw this pin with a 'dangling' indicator
62  PIN_DANGLING_HIDDEN = 4, // Draw (only!) the dangling indicator if the pin is hidden
63  PIN_DRAW_ELECTRICAL_TYPE_NAME = 8 // Draw the pin electrical type name
64  // used only in component editor and component viewer
65 };
66 
67 
68 class LIB_PIN : public LIB_ITEM
69 {
71  int m_length;
74  int m_width;
77  wxString m_name;
78  wxString m_number;
81 
97  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
98  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
99  const TRANSFORM& aTransform ) override;
100 
101 public:
102  LIB_PIN( LIB_PART* aParent );
103 
104  // Do not create a copy constructor. The one generated by the compiler is adequate.
105 
106  ~LIB_PIN() { }
107 
108  wxString GetClass() const override
109  {
110  return wxT( "LIB_PIN" );
111  }
112 
113 #if defined(DEBUG)
114  void Show( int nestLevel, std::ostream& os ) const override;
115 #endif
116 
117  bool Save( OUTPUTFORMATTER& aFormatter ) override;
118 
119  bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ) override;
120 
121  bool HitTest( const wxPoint& aPosition ) const override;
122 
123  bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const override;
124 
125  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
126 
133  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList, SCH_COMPONENT* aComponent );
134 
135  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
136 
137  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
138  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
139 
145  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
146 
152  wxPoint PinEndPoint() const;
153 
161  int PinDrawOrient( const TRANSFORM& aTransform ) const;
162 
163  const wxString& GetName() const
164  {
165  return m_name;
166  }
167 
176  void SetName( const wxString& aName, bool aTestOtherPins = true );
177 
187  void SetNameTextSize( int aSize, bool aTestOtherPins = true );
188 
189  int GetNameTextSize() const { return m_nameTextSize; }
190 
191  const wxString& GetNumber() const
192  {
193  return m_number;
194  }
195 
203  void SetNumber( const wxString& aNumber )
204  {
205  m_number = aNumber;
206  }
207 
217  void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
218 
219  int GetNumberTextSize() const { return m_numTextSize; }
220 
221  int GetOrientation() const { return m_orientation; }
222 
231  void SetOrientation( int aOrientation, bool aTestOtherPins = true );
232 
233  void Rotate() override;
234 
235  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
236 
244  void SetShape( GRAPHIC_PINSHAPE aShape );
245 
251  ELECTRICAL_PINTYPE GetType() const { return m_type; }
252 
259  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
260 
266  wxString const GetCanonicalElectricalTypeName() const
267  {
268  return GetCanonicalElectricalTypeName( m_type );
269  }
270 
275  wxString const GetElectricalTypeName() const
276  {
277  return GetText( m_type );
278  }
279 
289  void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
290 
299  void SetLength( int aLength, bool aTestOtherPins = true );
300 
301  int GetLength() { return m_length; }
302 
312  void SetPartNumber( int aPart );
313 
315  int GetPartNumber() const { return m_Unit; }
316 
326  void SetConversion( int aConversion );
327 
336  void SetVisible( bool aVisible );
337 
353  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
354 
360  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
361 
366  bool IsPowerConnection() const {
367 
368  return (
369  ( !IsVisible() && GetType() == PIN_POWER_IN )
370  ||
371  ( (LIB_PART*)GetParent()->IsPower() && GetType() == PIN_POWER_IN )
372  ) ; }
373 
374  int GetPenSize() const override;
375 
381  void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
382  int aOrientation, GR_DRAWMODE aDrawMode,
383  COLOR4D aColor = COLOR4D::UNSPECIFIED,
384  bool aDrawDangling = true,
385  bool aOnlyTarget = false );
386 
397  void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
398  int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
399  COLOR4D aColor, GR_DRAWMODE aDrawMode );
400 
406  void DrawPinElectricalTypeName( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
407  int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode );
408 
417  void PlotPinTexts( PLOTTER *aPlotter,
418  wxPoint& aPosition,
419  int aOrientation,
420  int aTextInside,
421  bool aDrawPinNum,
422  bool aDrawPinName,
423  int aWidth );
424 
425  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
426 
432  static wxArrayString GetOrientationNames();
433 
439  static const BITMAP_DEF* GetOrientationSymbols();
440 
448  static int GetOrientationCode( int aIndex );
449 
457  static int GetOrientationCodeIndex( int aCode );
458 
459  void SetOffset( const wxPoint& aOffset ) override;
460 
461  bool Inside( EDA_RECT& aRect ) const override;
462 
463  void Move( const wxPoint& aPosition ) override;
464 
465  wxPoint GetPosition() const override { return m_position; }
466 
473  void SetPinPosition( wxPoint aPosition );
474 
475  void MirrorHorizontal( const wxPoint& aCenter ) override;
476 
477  void MirrorVertical( const wxPoint& aCenter ) override;
478 
479  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
480 
481  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
482  const TRANSFORM& aTransform ) override;
483 
484  int GetWidth() const override { return m_width; }
485 
486  void SetWidth( int aWidth ) override;
487 
488  BITMAP_DEF GetMenuImage() const override;
489 
490  wxString GetSelectMenuText() const override;
491 
492  EDA_ITEM* Clone() const override;
493 
494 private:
500  void getMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
501 
502 
512  int compare( const LIB_ITEM& aOther ) const override;
513 };
514 
515 
516 #endif // CLASS_PIN_H
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:108
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:2301
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:1880
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:80
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:342
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:1874
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:1389
PNG memory record (file in memory).
Definition: bitmap_types.h:38
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:73
Electrical pin type handling.
int m_numTextSize
Definition: lib_pin.h:79
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:2028
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:2213
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:2281
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:277
LibPinDrawFlags
Definition: lib_pin.h:59
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:266
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:160
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:275
void SetWidth(int aWidth) override
Function SetWidth sets the width of the draw item to aWidth.
Definition: lib_pin.cpp:2018
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:315
void SetOffset(const wxPoint &aOffset) override
Function Offset sets the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1904
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
wxString m_name
Definition: lib_pin.h:77
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:2275
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:2061
Pin shape handling.
Definition: lib_pin.h:55
void EnableEditMode(bool aEnable, bool aEditPinByPin=false)
Enable or clear pin editing mode.
Definition: lib_pin.cpp:493
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:1602
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:138
int GetNameTextSize() const
Definition: lib_pin.h:189
int GetOrientation() const
Definition: lib_pin.h:221
int m_length
Length of the pin.
Definition: lib_pin.h:71
int GetWidth() const override
Function GetWidth return the width of the draw item.
Definition: lib_pin.h:484
static int GetOrientationCodeIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:2233
int GetNumberTextSize() const
Definition: lib_pin.h:219
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:191
void MirrorVertical(const wxPoint &aCenter) override
Function MirrorVertical mirrors the draw object along the MirrorVertical (Y) axis about aCenter point...
Definition: lib_pin.cpp:1940
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:901
const wxString & GetName() const
Definition: lib_pin.h:163
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:429
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.h:203
int GetPenSize() const override
Function GetPenSize.
Definition: lib_pin.cpp:895
bool Load(LINE_READER &aLineReader, wxString &aErrorMsg) override
Definition: lib_pin.cpp:682
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:72
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:78
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1451
~LIB_PIN()
Definition: lib_pin.h:106
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Class LIB_ITEM definition.
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:251
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:1910
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:519
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:460
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:2247
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:360
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:1175
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:145
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin edition.
Definition: lib_pin.cpp:372
wxPoint GetPosition() const override
Function GetPosition returns the current draw object position.
Definition: lib_pin.h:465
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:76
Base plotter engine class.
Definition: class_plotter.h:97
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:70
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:399
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:2001
wxPoint PinEndPoint() const
Function PinEndPoint.
Definition: lib_pin.cpp:1802
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:2287
Class EDA_RECT handles the component boundary box.
void SetType(ELECTRICAL_PINTYPE aType, bool aTestOtherPins=true)
Set the electrical type of the pin.
Definition: lib_pin.cpp:306
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:1918
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:75
DrawPinOrient
The component library pin object orientations.
Definition: lib_pin.h:52
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:366
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:248
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:192
int m_width
Line width of the pin.
Definition: lib_pin.h:74
int GetLength()
Definition: lib_pin.h:301
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:976
bool Save(OUTPUTFORMATTER &aFormatter) override
Function Save writes draw item object to aFormatter in component library "*.lib" format.
Definition: lib_pin.cpp:543
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:235
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:1829
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:220
void MirrorHorizontal(const wxPoint &aCenter) override
Function MirrorHorizontal mirrors the draw object along the horizontal (X) axis about aCenter point...
Definition: lib_pin.cpp:1928
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:2224
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39