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 
30 #ifndef CLASS_PIN_H
31 #define CLASS_PIN_H
32 
33 class SCH_COMPONENT;
34 
35 #include <eda_rect.h>
36 #include <lib_item.h>
37 
38 #include "pin_shape.h"
39 #include "pin_type.h"
40 #include "class_libentry.h"
41 
43 #define DEFAULT_PIN_NAME_OFFSET 40
44 
45 // Circle diameter drawn at the active end of pins:
46 #define TARGET_PIN_RADIUS Mils2iu( 15 )
47 
48 // Pin visibility flag bit:
49 #define PIN_INVISIBLE 1 // Set makes pin invisible
50 
51 
56  PIN_RIGHT = 'R',
57  PIN_LEFT = 'L',
58  PIN_UP = 'U',
59  PIN_DOWN = 'D'
60 };
61 
62 
63 class LIB_PIN : public LIB_ITEM
64 {
65  // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
66  // level, performing additional pin checking, multi-pin editing, and setting the modified
67  // flag. So the LEGACY_PLUGIN_CACHE needs direct access to the member variables.
69 
70  wxPoint m_position; // Position of the pin.
71  int m_length; // Length of the pin.
72  int m_orientation; // Pin orientation (Up, Down, Left, Right)
73  GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
74  int m_width; // Line width of the pin.
75  ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
76  int m_attributes; // Set bit 0 to indicate pin is invisible.
77  wxString m_name;
78  wxString m_number;
79  int m_numTextSize; // Pin num and Pin name sizes
81 
90  void print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
91  const TRANSFORM& aTransform ) override;
92 
93 public:
94  LIB_PIN( LIB_PART* aParent );
95 
96  // Do not create a copy constructor. The one generated by the compiler is adequate.
97 
98  ~LIB_PIN() { }
99 
100  wxString GetClass() const override
101  {
102  return wxT( "LIB_PIN" );
103  }
104 
105  wxString GetTypeName() override
106  {
107  return _( "Pin" );
108  }
109 
110 #if defined(DEBUG)
111  void Show( int nestLevel, std::ostream& os ) const override;
112 #endif
113 
114  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
115 
116  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
117 
124  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList,
125  SCH_COMPONENT* aComponent );
126 
127  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override;
128 
129  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
130  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
131 
136  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
137 
141  wxPoint PinEndPoint() const;
142 
149  int PinDrawOrient( const TRANSFORM& aTransform ) const;
150 
151  const wxString& GetName() const
152  {
153  return m_name;
154  }
155 
164  void SetName( const wxString& aName, bool aTestOtherPins = true );
165 
175  void SetNameTextSize( int aSize, bool aTestOtherPins = true );
176 
177  int GetNameTextSize() const { return m_nameTextSize; }
178 
179  const wxString& GetNumber() const
180  {
181  return m_number;
182  }
183 
191  void SetNumber( const wxString& aNumber );
192 
202  void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
203 
204  int GetNumberTextSize() const { return m_numTextSize; }
205 
206  int GetOrientation() const { return m_orientation; }
207 
216  void SetOrientation( int aOrientation, bool aTestOtherPins = true );
217 
218  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
219 
227  void SetShape( GRAPHIC_PINSHAPE aShape );
228 
234  ELECTRICAL_PINTYPE GetType() const { return m_type; }
235 
242  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
243 
249  wxString const GetCanonicalElectricalTypeName() const
250  {
252  }
253 
258  wxString const GetElectricalTypeName() const
259  {
260  return GetText( m_type );
261  }
262 
272  void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
273 
282  void SetLength( int aLength, bool aTestOtherPins = true );
283 
284  int GetLength() { return m_length; }
285 
295  void SetPartNumber( int aPart );
296 
298  int GetPartNumber() const { return m_Unit; }
299 
309  void SetConversion( int aConversion );
310 
319  void SetVisible( bool aVisible );
320 
338  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
339 
345  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
346 
351  bool IsPowerConnection() const
352  {
354  && ( !IsVisible() || (LIB_PART*) GetParent()->IsPower() );
355  }
356 
357  int GetPenWidth() const override;
358 
363  void PrintPinSymbol( RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrientation );
364 
373  void PrintPinTexts( RENDER_SETTINGS* aSettings, wxPoint& aPosition, int aOrientation,
374  int TextInside, bool DrawPinNum, bool DrawPinName );
375 
379  void PrintPinElectricalTypeName( RENDER_SETTINGS* aSettings, wxPoint& aPosition,
380  int aOrientation );
381 
389  void PlotPinTexts( PLOTTER *aPlotter, wxPoint& aPosition, int aOrientation,
390  int aTextInside, bool aDrawPinNum, bool aDrawPinName );
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  void MoveTo( const wxPoint& aPosition ) override;
429 
430  const wxPoint GetPosition() const override { return m_position; }
431 
438  void SetPinPosition( wxPoint aPosition );
439 
440  void MirrorHorizontal( const wxPoint& aCenter ) override;
441  void MirrorVertical( const wxPoint& aCenter ) override;
442  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
443 
444  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
445  const TRANSFORM& aTransform ) override;
446 
447  int GetWidth() const override { return m_width; }
448  void SetWidth( int aWidth ) override;
449 
450  BITMAP_DEF GetMenuImage() const override;
451 
452  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
453 
454  EDA_ITEM* Clone() const override;
455 
456  void CalcEdit( const wxPoint& aPosition ) override;
457 
458 private:
464  void getMsgPanelInfoBase( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList );
465 
466 
476  int compare( const LIB_ITEM& aOther,
477  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
478 };
479 
480 
481 #endif // CLASS_PIN_H
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:100
EDA_UNITS
Definition: common.h:196
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:1658
int m_nameTextSize
Definition: lib_pin.h:80
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:380
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1266
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:1367
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1216
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:708
PNG memory record (file in memory).
Definition: bitmap_def.h:29
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:73
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1667
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:1632
int m_numTextSize
Definition: lib_pin.h:79
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1612
int GetOrientation() const
Definition: lib_pin.h:206
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:1652
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:325
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:218
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:188
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:1421
void SetWidth(int aWidth) override
Definition: lib_pin.cpp:1411
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:81
wxString m_name
Definition: lib_pin.h:77
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:557
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1646
Pin shape handling.
Definition: lib_pin.h:58
void EnableEditMode(bool aEnable, bool aEditPinByPin=false)
Enable or clear pin editing mode.
Definition: lib_pin.cpp:531
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:130
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:1232
int m_length
Definition: lib_pin.h:71
int GetWidth() const override
Definition: lib_pin.h:447
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:1030
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:351
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:1355
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:467
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:249
int m_orientation
Definition: lib_pin.h:72
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
for transforming 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:902
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:258
~LIB_PIN()
Definition: lib_pin.h:98
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:116
const wxString & GetName() const
Definition: lib_pin.h:151
#define PIN_INVISIBLE
Definition: lib_pin.h:49
Class LIB_PIN definition.
wxString GetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:58
Define a library symbol object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:498
int GetPenWidth() const override
Definition: lib_pin.cpp:565
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:345
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:1272
int GetNameTextSize() const
Definition: lib_pin.h:177
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:571
const wxPoint GetPosition() const override
Definition: lib_pin.h:430
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:1698
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:160
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin editing.
Definition: lib_pin.cpp:410
int m_attributes
Definition: lib_pin.h:76
const wxString & GetNumber() const
Definition: lib_pin.h:179
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:234
Base plotter engine class.
Definition: plotter.h:104
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1333
wxPoint m_position
Definition: lib_pin.h:70
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:437
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:1396
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
#define _(s)
Definition: 3d_actions.cpp:33
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:352
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:163
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:75
DrawPinOrient
The component library pin object orientations.
Definition: lib_pin.h:55
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:296
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:249
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:221
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1327
int m_width
Definition: lib_pin.h:74
int GetLength()
Definition: lib_pin.h:284
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:105
void PrintPinSymbol(RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:599
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:298
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:850
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:268
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1343
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1623