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-2019 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 
42 // Circle diameter drawn at the active end of pins:
43 #define TARGET_PIN_RADIUS Mils2iu( 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 
68  int m_length;
71  int m_width;
74  wxString m_name;
75  wxString m_number;
78 
88  void print( wxDC* aDC, const wxPoint& aOffset, void* aData,
89  const TRANSFORM& aTransform ) override;
90 
91 public:
92  LIB_PIN( LIB_PART* aParent );
93 
94  // Do not create a copy constructor. The one generated by the compiler is adequate.
95 
96  ~LIB_PIN() { }
97 
98  wxString GetClass() const override
99  {
100  return wxT( "LIB_PIN" );
101  }
102 
103  wxString GetTypeName() override
104  {
105  return _( "Pin" );
106  }
107 
108 #if defined(DEBUG)
109  void Show( int nestLevel, std::ostream& os ) const override;
110 #endif
111 
112  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
113 
114  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
115 
122  void GetMsgPanelInfo(
123  EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList, SCH_COMPONENT* aComponent );
124 
125  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override;
126 
127  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
128  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
129 
134  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
135 
139  wxPoint PinEndPoint() const;
140 
147  int PinDrawOrient( const TRANSFORM& aTransform ) const;
148 
149  const wxString& GetName() const
150  {
151  return m_name;
152  }
153 
162  void SetName( const wxString& aName, bool aTestOtherPins = true );
163 
173  void SetNameTextSize( int aSize, bool aTestOtherPins = true );
174 
175  int GetNameTextSize() const { return m_nameTextSize; }
176 
177  const wxString& GetNumber() const
178  {
179  return m_number;
180  }
181 
189  void SetNumber( const wxString& aNumber );
190 
200  void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
201 
202  int GetNumberTextSize() const { return m_numTextSize; }
203 
204  int GetOrientation() const { return m_orientation; }
205 
214  void SetOrientation( int aOrientation, bool aTestOtherPins = true );
215 
216  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
217 
225  void SetShape( GRAPHIC_PINSHAPE aShape );
226 
232  ELECTRICAL_PINTYPE GetType() const { return m_type; }
233 
240  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
241 
247  wxString const GetCanonicalElectricalTypeName() const
248  {
250  }
251 
256  wxString const GetElectricalTypeName() const
257  {
258  return GetText( m_type );
259  }
260 
270  void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
271 
280  void SetLength( int aLength, bool aTestOtherPins = true );
281 
282  int GetLength() { return m_length; }
283 
293  void SetPartNumber( int aPart );
294 
296  int GetPartNumber() const { return m_Unit; }
297 
307  void SetConversion( int aConversion );
308 
317  void SetVisible( bool aVisible );
318 
336  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
337 
343  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
344 
349  bool IsPowerConnection() const
350  {
352  && ( !IsVisible() || (LIB_PART*) GetParent()->IsPower() );
353  }
354 
355  int GetPenSize() const override;
356 
361  void PrintPinSymbol( wxDC* aDC, const wxPoint& aPos, int aOrientation );
362 
371  void PrintPinTexts( wxDC* aDC, wxPoint& aPosition, int aOrientation, int TextInside,
372  bool DrawPinNum, bool DrawPinName );
373 
377  void PrintPinElectricalTypeName( wxDC* aDC, wxPoint& aPosition, int aOrientation );
378 
386  void PlotPinTexts( PLOTTER *aPlotter, wxPoint& aPosition, int aOrientation,
387  int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth );
388 
389  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
390 
396  static wxArrayString GetOrientationNames();
397 
403  static const BITMAP_DEF* GetOrientationSymbols();
404 
412  static int GetOrientationCode( int aIndex );
413 
421  static int GetOrientationIndex( int aCode );
422 
423  void Offset( const wxPoint& aOffset ) override;
424 
425  bool Inside( EDA_RECT& aRect ) const override;
426 
427  void MoveTo( const wxPoint& aPosition ) override;
428 
429  wxPoint GetPosition() const override { return m_position; }
430 
437  void SetPinPosition( wxPoint aPosition );
438 
439  void MirrorHorizontal( const wxPoint& aCenter ) override;
440  void MirrorVertical( const wxPoint& aCenter ) override;
441  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
442 
443  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
444  const TRANSFORM& aTransform ) override;
445 
446  int GetWidth() const override { return m_width; }
447  void SetWidth( int aWidth ) override;
448 
449  BITMAP_DEF GetMenuImage() const override;
450 
451  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
452 
453  EDA_ITEM* Clone() const override;
454 
455  void CalcEdit( const wxPoint& aPosition ) override;
456 
457 private:
463  void getMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList );
464 
465 
475  int compare( const LIB_ITEM& aOther ) const override;
476 };
477 
478 
479 #endif // CLASS_PIN_H
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:98
EDA_UNITS
Definition: common.h:72
power input (GND, VCC for ICs). Must be connected to a power output.
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:1240
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:1597
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:351
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1234
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:1312
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1184
PNG memory record (file in memory).
Definition: bitmap_def.h:29
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:70
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1606
Electrical pin type handling.
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1571
int m_numTextSize
Definition: lib_pin.h:76
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1551
int GetOrientation() const
Definition: lib_pin.h:204
void PrintPinTexts(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:678
LIB_PART * GetParent() const
Definition: lib_item.h:176
void PrintPinElectricalTypeName(wxDC *aDC, wxPoint &aPosition, int aOrientation)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:818
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1591
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:296
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:216
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:159
void SetWidth(int aWidth) override
Definition: lib_pin.cpp:1357
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:81
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:528
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1585
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:502
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:995
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:128
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:1200
int m_length
Length of the pin.
Definition: lib_pin.h:68
int GetWidth() const override
Definition: lib_pin.h:446
The base class for drawable items used by schematic library components.
Definition: lib_item.h:60
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:349
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:1300
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:438
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:220
int GetPenSize() const override
Definition: lib_pin.cpp:536
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:69
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:75
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:868
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:256
~LIB_PIN()
Definition: lib_pin.h:96
const wxString & GetName() const
Definition: lib_pin.h:149
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Class LIB_PIN definition.
wxString GetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:58
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:1270
Define a library symbol object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:469
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:343
int GetNameTextSize() const
Definition: lib_pin.h:175
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1637
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:146
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin editing.
Definition: lib_pin.cpp:381
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
wxPoint GetPosition() const override
Definition: lib_pin.h:429
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:73
const wxString & GetNumber() const
Definition: lib_pin.h:177
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:232
Base plotter engine class.
Definition: plotter.h:103
void MoveTo(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1278
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:408
int GetNumberTextSize() const
Definition: lib_pin.h:202
void getMsgPanelInfoBase(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1367
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:1341
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
#define _(s)
Definition: 3d_actions.cpp:31
void print(wxDC *aDC, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print a pin, with or without the pin texts.
Definition: lib_pin.cpp:548
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:323
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:89
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
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:267
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:247
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:192
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1264
int m_width
Line width of the pin.
Definition: lib_pin.h:71
int GetLength()
Definition: lib_pin.h:282
void PrintPinSymbol(wxDC *aDC, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:572
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:103
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:296
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:239
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1288
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1562