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-2017 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 <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 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  // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
63  // level, performing additional pin checking, multi-pin editing, and setting the modified
64  // flag. So the LEGACY_PLUGIN_CACHE needs direct access to the member variables.
66 
67  wxPoint m_position;
68  int m_length;
71  int m_width;
74  wxString m_name;
75  wxString m_number;
78 
89  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData,
90  const TRANSFORM& aTransform ) override;
91 
92 public:
93  LIB_PIN( LIB_PART* aParent );
94 
95  // Do not create a copy constructor. The one generated by the compiler is adequate.
96 
97  ~LIB_PIN() { }
98 
99  wxString GetClass() const override
100  {
101  return wxT( "LIB_PIN" );
102  }
103 
104  wxString GetTypeName() override
105  {
106  return _( "Pin" );
107  }
108 
109 #if defined(DEBUG)
110  void Show( int nestLevel, std::ostream& os ) const override;
111 #endif
112 
113  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
114 
115  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
116 
123  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList,
124  SCH_COMPONENT* aComponent );
125 
126  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
127 
128  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
129  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
130 
135  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
136 
140  wxPoint PinEndPoint() const;
141 
148  int PinDrawOrient( const TRANSFORM& aTransform ) const;
149 
150  const wxString& GetName() const
151  {
152  return m_name;
153  }
154 
163  void SetName( const wxString& aName, bool aTestOtherPins = true );
164 
174  void SetNameTextSize( int aSize, bool aTestOtherPins = true );
175 
176  int GetNameTextSize() const { return m_nameTextSize; }
177 
178  const wxString& GetNumber() const
179  {
180  return m_number;
181  }
182 
190  void SetNumber( const wxString& aNumber );
191 
201  void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
202 
203  int GetNumberTextSize() const { return m_numTextSize; }
204 
205  int GetOrientation() const { return m_orientation; }
206 
215  void SetOrientation( int aOrientation, bool aTestOtherPins = true );
216 
217  void Rotate() override;
218 
219  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
220 
228  void SetShape( GRAPHIC_PINSHAPE aShape );
229 
235  ELECTRICAL_PINTYPE GetType() const { return m_type; }
236 
243  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
244 
250  wxString const GetCanonicalElectricalTypeName() const
251  {
253  }
254 
259  wxString const GetElectricalTypeName() const
260  {
261  return GetText( m_type );
262  }
263 
273  void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
274 
283  void SetLength( int aLength, bool aTestOtherPins = true );
284 
285  int GetLength() { return m_length; }
286 
296  void SetPartNumber( int aPart );
297 
299  int GetPartNumber() const { return m_Unit; }
300 
310  void SetConversion( int aConversion );
311 
320  void SetVisible( bool aVisible );
321 
339  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
340 
346  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
347 
352  bool IsPowerConnection() const {
353  return GetType() == PIN_POWER_IN && ( !IsVisible() || (LIB_PART*) GetParent()->IsPower() );
354  }
355 
356  int GetPenSize() const override;
357 
362  void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPos,
363  int aOrientation );
364 
373  void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
374  int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName );
375 
379  void DrawPinElectricalTypeName( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
380  int aOrientation );
381 
389  void PlotPinTexts( PLOTTER *aPlotter, wxPoint& aPosition, int aOrientation,
390  int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth );
391 
392  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
393 
399  static wxArrayString GetOrientationNames();
400 
406  static const BITMAP_DEF* GetOrientationSymbols();
407 
415  static int GetOrientationCode( int aIndex );
416 
424  static int GetOrientationIndex( int aCode );
425 
426  void Offset( const wxPoint& aOffset ) override;
427 
428  bool Inside( EDA_RECT& aRect ) const override;
429 
430  void MoveTo( const wxPoint& aPosition ) override;
431 
432  wxPoint GetPosition() const override { return m_position; }
433 
440  void SetPinPosition( wxPoint aPosition );
441 
442  void MirrorHorizontal( const wxPoint& aCenter ) override;
443  void MirrorVertical( const wxPoint& aCenter ) override;
444  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
445 
446  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
447  const TRANSFORM& aTransform ) override;
448 
449  int GetWidth() const override { return m_width; }
450  void SetWidth( int aWidth ) override;
451 
452  BITMAP_DEF GetMenuImage() const override;
453 
454  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
455 
456  EDA_ITEM* Clone() const override;
457 
458  void CalcEdit( const wxPoint& aPosition ) override;
459 
460 private:
466  void getMsgPanelInfoBase( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList );
467 
468 
478  int compare( const LIB_ITEM& aOther ) const override;
479 };
480 
481 
482 #endif // CLASS_PIN_H
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:99
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1676
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:1293
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:77
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:364
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1287
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1237
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:70
Electrical pin type handling.
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1624
int m_numTextSize
Definition: lib_pin.h:76
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1604
int GetOrientation() const
Definition: lib_pin.h:205
LIB_PART * GetParent() const
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1661
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:299
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:219
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:162
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Draw a pin, with or without the pin texts.
Definition: lib_pin.cpp:561
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_pin.cpp:1410
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_draw_item.h:89
wxString m_name
Definition: lib_pin.h:74
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:541
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1655
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:515
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPosition, int aOrientation, int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1048
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:129
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:1253
int m_length
Length of the pin.
Definition: lib_pin.h:68
int GetWidth() const override
Return the width of the draw item.
Definition: lib_pin.h:449
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
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:352
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:1353
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:451
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:223
int GetPenSize() const override
Definition: lib_pin.cpp:549
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:69
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:75
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:922
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:259
~LIB_PIN()
Definition: lib_pin.h:97
const wxString & GetName() const
Definition: lib_pin.h:150
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Class LIB_ITEM definition.
bool Inside(EDA_RECT &aRect) const override
Test if any part of the draw object is inside rectangle bounds of aRect.
Definition: lib_pin.cpp:1323
void DrawPinElectricalTypeName(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:869
Define a library symbol object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:482
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:1638
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:346
int GetNameTextSize() const
Definition: lib_pin.h:176
void DrawPinSymbol(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPos, int aOrientation)
Draw the pin symbol without text.
Definition: lib_pin.cpp:602
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1713
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:148
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1667
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin editing.
Definition: lib_pin.cpp:394
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:432
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:73
const wxString & GetNumber() const
Definition: lib_pin.h:178
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:235
Base plotter engine class.
Definition: plotter.h:97
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1331
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:67
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:421
int GetNumberTextSize() const
Definition: lib_pin.h:203
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:1394
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetType(ELECTRICAL_PINTYPE aType, bool aTestOtherPins=true)
Set the electrical type of the pin.
Definition: lib_pin.cpp:328
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:72
DrawPinOrient
The component library pin object orientations.
Definition: lib_pin.h:52
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:270
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:250
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:195
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1317
int m_width
Line width of the pin.
Definition: lib_pin.h:71
int GetLength()
Definition: lib_pin.h:285
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:104
EDA_UNITS_T
Definition: common.h:157
void DrawPinTexts(EDA_DRAW_PANEL *aPanel, wxDC *aDC, 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:724
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:299
void getMsgPanelInfoBase(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1420
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:242
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1341
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1615