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 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 {
70  // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
71  // level, performing additional pin checking, multi-pin editing, and setting the modified
72  // flag. So the LEGACY_PLUGIN_CACHE needs direct access to the member variables.
74 
76  int m_length;
79  int m_width;
82  wxString m_name;
83  wxString m_number;
86 
102  void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
103  COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
104  const TRANSFORM& aTransform ) override;
105 
106 public:
107  LIB_PIN( LIB_PART* aParent );
108 
109  // Do not create a copy constructor. The one generated by the compiler is adequate.
110 
111  ~LIB_PIN() { }
112 
113  wxString GetClass() const override
114  {
115  return wxT( "LIB_PIN" );
116  }
117 
118  wxString GetTypeName() override
119  {
120  return _( "Pin" );
121  }
122 
123 #if defined(DEBUG)
124  void Show( int nestLevel, std::ostream& os ) const override;
125 #endif
126 
127  bool HitTest( const wxPoint& aPosition ) const override;
128 
129  bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const override;
130 
131  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
132 
139  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList, SCH_COMPONENT* aComponent );
140 
141  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
142 
143  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
144  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
145 
150  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles ) const;
151 
155  wxPoint PinEndPoint() const;
156 
163  int PinDrawOrient( const TRANSFORM& aTransform ) const;
164 
165  const wxString& GetName() const
166  {
167  return m_name;
168  }
169 
178  void SetName( const wxString& aName, bool aTestOtherPins = true );
179 
189  void SetNameTextSize( int aSize, bool aTestOtherPins = true );
190 
191  int GetNameTextSize() const { return m_nameTextSize; }
192 
193  const wxString& GetNumber() const
194  {
195  return m_number;
196  }
197 
205  void SetNumber( const wxString& aNumber );
206 
216  void SetNumberTextSize( int aSize, bool aTestOtherPins = true );
217 
218  int GetNumberTextSize() const { return m_numTextSize; }
219 
220  int GetOrientation() const { return m_orientation; }
221 
230  void SetOrientation( int aOrientation, bool aTestOtherPins = true );
231 
232  void Rotate() override;
233 
234  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
235 
243  void SetShape( GRAPHIC_PINSHAPE aShape );
244 
250  ELECTRICAL_PINTYPE GetType() const { return m_type; }
251 
258  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
259 
265  wxString const GetCanonicalElectricalTypeName() const
266  {
267  return GetCanonicalElectricalTypeName( m_type );
268  }
269 
274  wxString const GetElectricalTypeName() const
275  {
276  return GetText( m_type );
277  }
278 
288  void SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins = true );
289 
298  void SetLength( int aLength, bool aTestOtherPins = true );
299 
300  int GetLength() { return m_length; }
301 
311  void SetPartNumber( int aPart );
312 
314  int GetPartNumber() const { return m_Unit; }
315 
325  void SetConversion( int aConversion );
326 
335  void SetVisible( bool aVisible );
336 
354  void EnableEditMode( bool aEnable, bool aEditPinByPin = false );
355 
361  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
362 
367  bool IsPowerConnection() const {
368 
369  return (
370  ( !IsVisible() && GetType() == PIN_POWER_IN )
371  ||
372  ( (LIB_PART*)GetParent()->IsPower() && GetType() == PIN_POWER_IN )
373  ) ; }
374 
375  int GetPenSize() const override;
376 
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 
396  void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
397  int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
398  COLOR4D aColor, GR_DRAWMODE aDrawMode );
399 
404  void DrawPinElectricalTypeName( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
405  int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode );
406 
414  void PlotPinTexts( PLOTTER *aPlotter,
415  wxPoint& aPosition,
416  int aOrientation,
417  int aTextInside,
418  bool aDrawPinNum,
419  bool aDrawPinName,
420  int aWidth );
421 
422  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
423 
429  static wxArrayString GetOrientationNames();
430 
436  static const BITMAP_DEF* GetOrientationSymbols();
437 
445  static int GetOrientationCode( int aIndex );
446 
454  static int GetOrientationCodeIndex( int aCode );
455 
456  void SetOffset( const wxPoint& aOffset ) override;
457 
458  bool Inside( EDA_RECT& aRect ) const override;
459 
460  void Move( const wxPoint& aPosition ) override;
461 
462  wxPoint GetPosition() const override { return m_position; }
463 
470  void SetPinPosition( wxPoint aPosition );
471 
472  void MirrorHorizontal( const wxPoint& aCenter ) override;
473 
474  void MirrorVertical( const wxPoint& aCenter ) override;
475 
476  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
477 
478  void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
479  const TRANSFORM& aTransform ) override;
480 
481  int GetWidth() const override { return m_width; }
482 
483  void SetWidth( int aWidth ) override;
484 
485  BITMAP_DEF GetMenuImage() const override;
486 
487  wxString GetSelectMenuText() const override;
488 
489  EDA_ITEM* Clone() const override;
490 
491 private:
497  void getMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
498 
499 
509  int compare( const LIB_ITEM& aOther ) const override;
510 };
511 
512 
513 #endif // CLASS_PIN_H
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:113
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1969
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:1548
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:85
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:362
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1542
void DrawPinElectricalTypeName(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Draw the electrical type text of the pin (only for the footprint editor) aDrawMode = GR_OR...
Definition: lib_pin.cpp:1057
PNG memory record (file in memory).
Definition: bitmap_types.h:41
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:78
Electrical pin type handling.
int m_numTextSize
Definition: lib_pin.h:84
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1696
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1881
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1949
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:297
LibPinDrawFlags
Definition: lib_pin.h:59
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:265
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:274
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_pin.cpp:1686
int GetPartNumber() const
Get the pin part number.
Definition: lib_pin.h:314
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1572
int m_Unit
Unit identification for multiple parts per package.
wxString m_name
Definition: lib_pin.h:82
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1943
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_pin.cpp:1729
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:513
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:1270
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:144
int GetNameTextSize() const
Definition: lib_pin.h:191
int GetOrientation() const
Definition: lib_pin.h:220
int m_length
Length of the pin.
Definition: lib_pin.h:76
int GetWidth() const override
Return the width of the draw item.
Definition: lib_pin.h:481
static int GetOrientationCodeIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1901
int GetNumberTextSize() const
Definition: lib_pin.h:218
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
const wxString & GetNumber() const
Definition: lib_pin.h:193
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:1608
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:569
const wxString & GetName() const
Definition: lib_pin.h:165
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:449
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:221
int GetPenSize() const override
Definition: lib_pin.cpp:563
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:77
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:83
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1119
~LIB_PIN()
Definition: lib_pin.h:111
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
#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:250
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:1578
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:539
Define a library symbol object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:480
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:1915
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:361
void DrawPinTexts(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:843
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 edition.
Definition: lib_pin.cpp:392
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:462
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:81
Base plotter engine class.
Definition: plotter.h:96
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:75
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:419
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:1669
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1470
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:1955
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:326
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1586
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:180
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:80
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:367
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:268
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:193
int m_width
Line width of the pin.
Definition: lib_pin.h:79
int GetLength()
Definition: lib_pin.h:300
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)
Draw the pin symbol without text.
Definition: lib_pin.cpp:644
wxString GetTypeName() override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:118
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:234
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:1497
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:240
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1596
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1892
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39