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 
26 
27 #ifndef CLASS_PIN_H
28 #define CLASS_PIN_H
29 
30 class SCH_COMPONENT;
31 
32 #include <eda_rect.h>
33 #include <lib_item.h>
34 #include <pin_type.h>
35 #include <class_libentry.h>
36 
37 // Circle diameter drawn at the active end of pins:
38 #define TARGET_PIN_RADIUS Mils2iu( 15 )
39 
40 // Pin visibility flag bit:
41 #define PIN_INVISIBLE 1 // Set makes pin invisible
42 
43 
48  PIN_RIGHT = 'R',
49  PIN_LEFT = 'L',
50  PIN_UP = 'U',
51  PIN_DOWN = 'D'
52 };
53 
54 
55 class LIB_PIN : public LIB_ITEM
56 {
57 public:
58  struct ALT
59  {
60  wxString m_Name;
61  GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin
62  ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin.
63  };
64 
65 protected:
66  wxPoint m_position; // Position of the pin.
67  int m_length; // Length of the pin.
68  int m_orientation; // Pin orientation (Up, Down, Left, Right)
69  GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
70  ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
71  int m_attributes; // Set bit 0 to indicate pin is invisible.
72  wxString m_name;
73  wxString m_number;
74  int m_numTextSize; // Pin num and Pin name sizes
76 
77  std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
78 
79 protected:
84  void printPinSymbol( RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrientation );
85 
94  void printPinTexts( RENDER_SETTINGS* aSettings, wxPoint& aPinPos, int aPinOrient,
95  int aTextInside, bool aDrawPinNum, bool aDrawPinName );
96 
100  void printPinElectricalTypeName( RENDER_SETTINGS* aSettings, wxPoint& aPosition,
101  int aOrientation );
102 
103 public:
110  static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
111 
112 public:
113  ~LIB_PIN() { }
114 
115  wxString GetClass() const override
116  {
117  return wxT( "LIB_PIN" );
118  }
119 
120  wxString GetTypeName() const override
121  {
122  return _( "Pin" );
123  }
124 
125  int GetOrientation() const { return m_orientation; }
126  void SetOrientation( int aOrientation ) { m_orientation = aOrientation; }
127 
128  GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
129  void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
130 
131  int GetLength() const { return m_length; }
132  void SetLength( int aLength ) { m_length = aLength; }
133 
134  ELECTRICAL_PINTYPE GetType() const { return m_type; }
135  void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; }
136 
137  wxString const GetCanonicalElectricalTypeName() const
138  {
140  }
141 
142  wxString const GetElectricalTypeName() const
143  {
145  }
146 
147  bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
148  void SetVisible( bool aVisible )
149  {
150  if( aVisible )
152  else
154  }
155 
156  const wxString& GetName() const { return m_name; }
157  void SetName( const wxString& aName )
158  {
159  m_name = aName;
160 
161  // pin name string does not support spaces
162  m_name.Replace( wxT( " " ), wxT( "_" ) );
163  }
164 
165  const wxString& GetNumber() const { return m_number; }
166  void SetNumber( const wxString& aNumber )
167  {
168  m_number = aNumber;
169 
170  // pin number string does not support spaces
171  m_number.Replace( wxT( " " ), wxT( "_" ) );
172  }
173 
174  int GetNameTextSize() const { return m_nameTextSize; }
175  void SetNameTextSize( int aSize ) { m_nameTextSize = aSize; }
176 
177  int GetNumberTextSize() const { return m_numTextSize; }
178  void SetNumberTextSize( int aSize ) { m_numTextSize = aSize; }
179 
180  std::map<wxString, ALT>& GetAlternates() { return m_alternates; }
181 
182  ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; }
183 
192  void print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
193  const TRANSFORM& aTransform ) override;
194 
201  int PinDrawOrient( const TRANSFORM& aTransform ) const;
202 
203  LIB_PIN( LIB_PART* aParent );
204 
205  LIB_PIN( LIB_PART* aParent, const wxString& aName, const wxString& aNumber, int aOrientation,
206  ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize, int aNumTextSize,
207  int aConvert, const wxPoint& aPos, int aUnit );
208 
209  // Do not create a copy constructor. The one generated by the compiler is adequate.
210 
211 #if defined(DEBUG)
212  void Show( int nestLevel, std::ostream& os ) const override;
213 #endif
214 
215  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
216 
217  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
218 
219  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
220 
221  /* Cannot use a default parameter here as it will not be compatible with the virtual. */
222  const EDA_RECT GetBoundingBox() const override { return GetBoundingBox( false ); }
223 
228  const EDA_RECT GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly = false ) const;
229 
234  bool IsPowerConnection() const
235  {
237  && ( !IsVisible() || (LIB_PART*) GetParent()->IsPower() );
238  }
239 
240  int GetPenWidth() const override;
241 
249  void PlotPinTexts( PLOTTER *aPlotter, wxPoint& aPinPos, int aPinOrient,
250  int aTextInside, bool aDrawPinNum, bool aDrawPinName );
251 
252  void PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation );
253 
254  void Offset( const wxPoint& aOffset ) override;
255 
256  void MoveTo( const wxPoint& aNewPosition ) override;
257 
258  wxPoint GetPosition() const override { return m_position; }
259  void SetPosition( const wxPoint& aPos ) override { m_position = aPos; }
260 
261  void MirrorHorizontal( const wxPoint& aCenter ) override;
262  void MirrorVertical( const wxPoint& aCenter ) override;
263  void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
264 
265  void Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
266  const TRANSFORM& aTransform ) override;
267 
268  // Get/SetWidth() not used for pins. Use GetPenWidth() for drawing.
269  int GetWidth() const override { return 1; }
270  void SetWidth( int aWidth ) override { };
271 
272  BITMAP_DEF GetMenuImage() const override;
273 
274  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
275 
276  EDA_ITEM* Clone() const override;
277 
278  void CalcEdit( const wxPoint& aPosition ) override;
279 
280 private:
290  int compare( const LIB_ITEM& aOther,
291  LIB_ITEM::COMPARE_FLAGS aCompareFlags = LIB_ITEM::COMPARE_FLAGS::NORMAL ) const override;
292 };
293 
294 
295 #endif // CLASS_PIN_H
void SetNumberTextSize(int aSize)
Definition: lib_pin.h:178
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:115
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:463
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:1135
int m_nameTextSize
Definition: lib_pin.h:75
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:831
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:931
PNG memory record (file in memory).
Definition: bitmap_def.h:29
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:69
void SetOrientation(int aOrientation)
Definition: lib_pin.h:126
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
void printPinTexts(RENDER_SETTINGS *aSettings, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:313
void MoveTo(const wxPoint &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:895
int m_numTextSize
Definition: lib_pin.h:74
int GetOrientation() const
Definition: lib_pin.h:125
LIB_PART * GetParent() const
Definition: lib_item.h:183
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1129
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:240
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:129
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
void printPinSymbol(RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:202
void SetWidth(int aWidth) override
Definition: lib_pin.h:270
void SetLength(int aLength)
Definition: lib_pin.h:132
wxString m_name
Definition: lib_pin.h:72
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:143
ALT GetAlt(const wxString &aAlt)
Definition: lib_pin.h:182
Definition: lib_pin.h:50
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:222
GRAPHIC_PINSHAPE
Definition: pin_type.h:53
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:797
void SetPosition(const wxPoint &aPos) override
Definition: lib_pin.h:259
int m_length
Definition: lib_pin.h:67
int GetWidth() const override
Definition: lib_pin.h:269
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:62
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
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:234
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:918
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:166
int m_orientation
Definition: lib_pin.h:68
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:135
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:73
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:516
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:142
~LIB_PIN()
Definition: lib_pin.h:113
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:117
const wxString & GetName() const
Definition: lib_pin.h:156
#define PIN_INVISIBLE
Definition: lib_pin.h:41
Define a library symbol object.
wxString m_Name
Definition: lib_pin.h:60
void SetVisible(bool aVisible)
Definition: lib_pin.h:148
int GetPenWidth() const override
Definition: lib_pin.cpp:168
bool IsVisible() const
Definition: lib_pin.h:147
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:837
int GetNameTextSize() const
Definition: lib_pin.h:174
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:174
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:645
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.
Definition: lib_pin.cpp:975
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1168
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:96
wxPoint GetPosition() const override
Definition: lib_pin.h:258
int m_attributes
Definition: lib_pin.h:71
EDA_UNITS
Definition: eda_units.h:38
const wxString & GetNumber() const
Definition: lib_pin.h:165
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:134
Base plotter engine class.
Definition: plotter.h:131
std::map< wxString, ALT > m_alternates
Definition: lib_pin.h:77
wxPoint m_position
Definition: lib_pin.h:66
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:180
int GetNumberTextSize() const
Definition: lib_pin.h:177
bool IsPower() const
void SetName(const wxString &aName)
Definition: lib_pin.h:157
void SetNameTextSize(int aSize)
Definition: lib_pin.h:175
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:34
int GetLength() const
Definition: lib_pin.h:131
#define _(s)
Definition: 3d_actions.cpp:33
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Schematic symbol object.
Definition: sch_component.h:79
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:70
DrawPinOrient
The component library pin object orientations.
Definition: lib_pin.h:47
wxString GetTypeName() const override
Provide a user-consumable name of the object type.
Definition: lib_pin.h:120
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:137
void Plot(PLOTTER *aPlotter, const wxPoint &aPffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:960
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:889
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:61
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:905