2011-10-31 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-28 16:56:09 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras at wanadoo.fr
|
2017-11-27 15:18:30 +00:00
|
|
|
* Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-02-09 17:18:56 +00:00
|
|
|
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-31 20:49:48 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
|
2010-03-04 09:32:51 +00:00
|
|
|
#ifndef CLASS_PIN_H
|
|
|
|
#define CLASS_PIN_H
|
|
|
|
|
2019-08-15 07:09:52 +00:00
|
|
|
#include <lib_item.h>
|
2020-08-21 15:54:24 +00:00
|
|
|
#include <pin_type.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <lib_symbol.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2016-11-04 11:13:22 +00:00
|
|
|
// Circle diameter drawn at the active end of pins:
|
2022-09-16 23:42:20 +00:00
|
|
|
#define TARGET_PIN_RADIUS schIUScale.MilsToIU( 15 )
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2016-11-04 11:13:22 +00:00
|
|
|
// Pin visibility flag bit:
|
|
|
|
#define PIN_INVISIBLE 1 // Set makes pin invisible
|
2010-03-04 09:32:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-14 18:00:08 +00:00
|
|
|
* The symbol library pin object orientations.
|
2010-03-04 09:32:51 +00:00
|
|
|
*/
|
|
|
|
enum DrawPinOrient {
|
|
|
|
PIN_RIGHT = 'R',
|
|
|
|
PIN_LEFT = 'L',
|
|
|
|
PIN_UP = 'U',
|
2010-10-04 12:58:07 +00:00
|
|
|
PIN_DOWN = 'D'
|
2010-03-04 09:32:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
class LIB_PIN : public LIB_ITEM
|
2010-03-04 09:32:51 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
public:
|
|
|
|
struct ALT
|
|
|
|
{
|
|
|
|
wxString m_Name;
|
|
|
|
GRAPHIC_PINSHAPE m_Shape; // Shape drawn around pin
|
|
|
|
ELECTRICAL_PINTYPE m_Type; // Electrical type of the pin.
|
|
|
|
};
|
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
~LIB_PIN() { }
|
2011-12-08 21:05:43 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
wxString GetClass() const override
|
|
|
|
{
|
|
|
|
return wxT( "LIB_PIN" );
|
|
|
|
}
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
wxString GetTypeName() const override
|
2020-08-03 21:12:29 +00:00
|
|
|
{
|
|
|
|
return _( "Pin" );
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetOrientation() const { return m_orientation; }
|
|
|
|
void SetOrientation( int aOrientation ) { m_orientation = aOrientation; }
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2016-02-28 17:33:29 +00:00
|
|
|
GRAPHIC_PINSHAPE GetShape() const { return m_shape; }
|
2020-08-03 21:12:29 +00:00
|
|
|
void SetShape( GRAPHIC_PINSHAPE aShape ) { m_shape = aShape; }
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
int GetLength() const { return m_length; }
|
|
|
|
void SetLength( int aLength ) { m_length = aLength; }
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2022-07-11 17:55:54 +00:00
|
|
|
/**
|
|
|
|
* Change the length of a pin and adjust its position based on orientation.
|
|
|
|
*
|
|
|
|
* @param aLength New length of pin
|
|
|
|
*/
|
|
|
|
void ChangeLength( int aLength );
|
|
|
|
|
2016-02-19 16:51:23 +00:00
|
|
|
ELECTRICAL_PINTYPE GetType() const { return m_type; }
|
2020-08-03 21:12:29 +00:00
|
|
|
void SetType( ELECTRICAL_PINTYPE aType ) { m_type = aType; }
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2015-04-02 18:51:47 +00:00
|
|
|
wxString const GetCanonicalElectricalTypeName() const
|
|
|
|
{
|
|
|
|
return GetCanonicalElectricalTypeName( m_type );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString const GetElectricalTypeName() const
|
|
|
|
{
|
2020-07-29 15:03:40 +00:00
|
|
|
return ElectricalPinTypeGetText( m_type );
|
2015-04-02 18:51:47 +00:00
|
|
|
}
|
2011-02-08 12:01:14 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
bool IsVisible() const { return ( m_attributes & PIN_INVISIBLE ) == 0; }
|
|
|
|
void SetVisible( bool aVisible )
|
|
|
|
{
|
|
|
|
if( aVisible )
|
|
|
|
m_attributes &= ~PIN_INVISIBLE;
|
|
|
|
else
|
|
|
|
m_attributes |= PIN_INVISIBLE;
|
|
|
|
}
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
const wxString& GetName() const { return m_name; }
|
2021-06-12 18:54:34 +00:00
|
|
|
wxString GetShownName() const;
|
2020-08-03 21:12:29 +00:00
|
|
|
void SetName( const wxString& aName )
|
|
|
|
{
|
|
|
|
m_name = aName;
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
// pin name string does not support spaces
|
|
|
|
m_name.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
}
|
2010-12-07 16:10:42 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
const wxString& GetNumber() const { return m_number; }
|
2021-06-12 18:54:34 +00:00
|
|
|
wxString GetShownNumber() const { return m_number; }
|
2020-08-03 21:12:29 +00:00
|
|
|
void SetNumber( const wxString& aNumber )
|
|
|
|
{
|
|
|
|
m_number = aNumber;
|
|
|
|
|
|
|
|
// pin number string does not support spaces
|
|
|
|
m_number.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetNameTextSize() const { return m_nameTextSize; }
|
|
|
|
void SetNameTextSize( int aSize ) { m_nameTextSize = aSize; }
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
int GetNumberTextSize() const { return m_numTextSize; }
|
|
|
|
void SetNumberTextSize( int aSize ) { m_numTextSize = aSize; }
|
2015-03-27 10:26:07 +00:00
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
std::map<wxString, ALT>& GetAlternates() { return m_alternates; }
|
|
|
|
|
|
|
|
ALT GetAlt( const wxString& aAlt ) { return m_alternates[ aAlt ]; }
|
|
|
|
|
2010-03-04 09:32:51 +00:00
|
|
|
/**
|
2020-08-03 21:12:29 +00:00
|
|
|
* Print a pin, with or without the pin texts
|
2010-03-04 09:32:51 +00:00
|
|
|
*
|
2020-08-03 21:12:29 +00:00
|
|
|
* @param aOffset Offset to draw
|
|
|
|
* @param aData = used here as a boolean indicating whether or not to draw the pin
|
|
|
|
* electrical types
|
|
|
|
* @param aTransform Transform Matrix (rotation, mirror ..)
|
2010-03-04 09:32:51 +00:00
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
void print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, void* aData,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed ) override;
|
2010-03-04 09:32:51 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-03 21:12:29 +00:00
|
|
|
* Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
|
|
|
|
* according to its orientation and the matrix transform (rot, mirror) \a aTransform.
|
2010-03-04 09:32:51 +00:00
|
|
|
*
|
2020-08-03 21:12:29 +00:00
|
|
|
* @param aTransform Transform matrix
|
2010-03-04 09:32:51 +00:00
|
|
|
*/
|
2020-08-03 21:12:29 +00:00
|
|
|
int PinDrawOrient( const TRANSFORM& aTransform ) const;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_PIN( LIB_SYMBOL* aParent );
|
2020-08-03 21:12:29 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber, int aOrientation,
|
2020-09-13 14:54:19 +00:00
|
|
|
ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize, int aNumTextSize,
|
2022-01-01 06:04:08 +00:00
|
|
|
int aConvert, const VECTOR2I& aPos, int aUnit );
|
2020-09-13 14:54:19 +00:00
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
// Do not create a copy constructor. The one generated by the compiler is adequate.
|
|
|
|
|
2023-02-09 17:18:56 +00:00
|
|
|
// No, LIB_PINs don't really have operating poinst. But we draw SCH_PINs through their LIB_PIN
|
|
|
|
// counterparts, so here we are....
|
|
|
|
const wxString& GetOperatingPoint() const { return m_operatingPoint; }
|
|
|
|
void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
|
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void Show( int nestLevel, std::ostream& os ) const override;
|
|
|
|
#endif
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
|
2020-08-03 21:12:29 +00:00
|
|
|
|
2022-08-31 09:33:46 +00:00
|
|
|
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
|
2020-08-03 21:12:29 +00:00
|
|
|
|
|
|
|
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2022-07-23 22:26:03 +00:00
|
|
|
const BOX2I ViewBBox() const override;
|
|
|
|
|
2022-02-06 17:45:17 +00:00
|
|
|
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
|
|
|
|
2020-08-03 21:12:29 +00:00
|
|
|
/* Cannot use a default parameter here as it will not be compatible with the virtual. */
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I GetBoundingBox() const override { return GetBoundingBox( false, true, false ); }
|
2010-03-04 09:32:51 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-03 21:12:29 +00:00
|
|
|
* @param aIncludeInvisibles - if false, do not include labels for invisible pins
|
|
|
|
* in the calculation.
|
2010-03-04 09:32:51 +00:00
|
|
|
*/
|
2022-08-31 09:15:42 +00:00
|
|
|
const BOX2I GetBoundingBox( bool aIncludeInvisiblePins, bool aIncludeNameAndNumber,
|
|
|
|
bool aIncludeElectricalType ) const;
|
2015-07-20 19:49:32 +00:00
|
|
|
|
|
|
|
/**
|
2023-01-18 15:06:46 +00:00
|
|
|
* Return whether this pin forms a global power connection: i.e., is part of
|
|
|
|
* a power symbol and of type POWER_IN, or is a legacy invisible global
|
|
|
|
* power pin on a symbol.
|
2015-07-20 19:49:32 +00:00
|
|
|
*/
|
2023-01-18 15:06:46 +00:00
|
|
|
bool IsGlobalPower() const
|
2020-01-18 20:51:28 +00:00
|
|
|
{
|
|
|
|
return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
|
2021-06-10 18:51:46 +00:00
|
|
|
&& ( !IsVisible() || (LIB_SYMBOL*) GetParent()->IsPower() );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int GetPenWidth() const override;
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2011-10-31 20:49:48 +00:00
|
|
|
/**
|
2017-12-01 16:49:19 +00:00
|
|
|
* Plot the pin number and pin text info, given the pin line coordinates.
|
2011-10-31 20:49:48 +00:00
|
|
|
* Same as DrawPinTexts((), but output is the plotter
|
|
|
|
* The line must be vertical or horizontal.
|
|
|
|
* If TextInside then the text is been put inside (moving from x1, y1 in
|
|
|
|
* the opposite direction to x2,y2), otherwise all is drawn outside.
|
|
|
|
*/
|
2022-09-16 16:20:36 +00:00
|
|
|
void PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, int aPinOrient, int aTextInside,
|
|
|
|
bool aDrawPinNum, bool aDrawPinName, bool aDimmed ) const;
|
2010-03-04 09:32:51 +00:00
|
|
|
|
2022-09-16 16:20:36 +00:00
|
|
|
void PlotSymbol( PLOTTER *aPlotter, const VECTOR2I &aPosition, int aOrientation,
|
|
|
|
bool aDimmed ) const;
|
2011-06-17 13:24:22 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void Offset( const VECTOR2I& aOffset ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void MoveTo( const VECTOR2I& aNewPosition ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GetPosition() const override { return m_position; }
|
|
|
|
void SetPosition( const VECTOR2I& aPos ) override { m_position = aPos; }
|
2016-10-18 16:59:26 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I GetPinRoot() const;
|
2021-09-24 15:19:21 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void MirrorHorizontal( const VECTOR2I& aCenter ) override;
|
|
|
|
void MirrorVertical( const VECTOR2I& aCenter ) override;
|
|
|
|
void Rotate( const VECTOR2I& aCenter, bool aRotateCCW = true ) override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2022-02-10 19:49:25 +00:00
|
|
|
void Plot( PLOTTER* aPlotter, bool aBackground, const VECTOR2I& aOffset,
|
2022-09-16 16:20:36 +00:00
|
|
|
const TRANSFORM& aTransform, bool aDimmed ) const override;
|
2012-02-27 23:02:08 +00:00
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS GetMenuImage() const override;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2023-01-12 03:27:44 +00:00
|
|
|
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
EDA_ITEM* Clone() const override;
|
2012-03-17 14:39:27 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void CalcEdit( const VECTOR2I& aPosition ) override;
|
2018-08-03 12:18:26 +00:00
|
|
|
|
2021-03-25 14:07:16 +00:00
|
|
|
/**
|
|
|
|
* Return a string giving the electrical type of a pin.
|
|
|
|
*
|
|
|
|
* Can be used when a known, not translated name is needed (for instance in net lists)
|
|
|
|
*
|
|
|
|
* @param aType is the electrical type (see enum ELECTRICAL_PINTYPE )
|
|
|
|
* @return The electrical name for a pin type (see enun MsgPinElectricType for names).
|
|
|
|
*/
|
|
|
|
static const wxString GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE aType );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Print the pin symbol without text.
|
|
|
|
* If \a aColor != 0, draw with \a aColor, else with the normal pin color.
|
|
|
|
*/
|
2022-09-16 16:20:36 +00:00
|
|
|
void printPinSymbol( const RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, int aOrientation,
|
|
|
|
bool aDimmed );
|
2021-03-25 14:07:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Put the pin number and pin text info, given the pin line coordinates.
|
|
|
|
* The line must be vertical or horizontal.
|
|
|
|
* If aDrawPinName == false the pin name is not printed.
|
|
|
|
* If aDrawPinNum = false the pin number is not printed.
|
|
|
|
* If aTextInside then the text is been put inside,otherwise all is drawn outside.
|
|
|
|
* Pin Name: substring between '~' is negated
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
void printPinTexts( const RENDER_SETTINGS* aSettings, VECTOR2I& aPinPos, int aPinOrient,
|
2022-09-16 16:20:36 +00:00
|
|
|
int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed );
|
2021-03-25 14:07:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the electrical type text of the pin (only for the footprint editor)
|
|
|
|
*/
|
2022-01-01 06:04:08 +00:00
|
|
|
void printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, VECTOR2I& aPosition,
|
2022-09-16 16:20:36 +00:00
|
|
|
int aOrientation, bool aDimmed );
|
2021-03-25 14:07:16 +00:00
|
|
|
|
2012-02-27 23:02:08 +00:00
|
|
|
private:
|
2010-03-04 09:32:51 +00:00
|
|
|
/**
|
2012-03-26 23:47:08 +00:00
|
|
|
* @copydoc LIB_ITEM::compare()
|
2010-03-04 09:32:51 +00:00
|
|
|
*
|
2012-03-26 23:47:08 +00:00
|
|
|
* The pin specific sort order is as follows:
|
2010-03-04 09:32:51 +00:00
|
|
|
* - Pin number.
|
|
|
|
* - Pin name, case insensitive compare.
|
|
|
|
* - Pin horizontal (X) position.
|
|
|
|
* - Pin vertical (Y) position.
|
|
|
|
*/
|
2022-03-03 12:20:30 +00:00
|
|
|
int compare( const LIB_ITEM& aOther, int aCompareFlags = 0 ) const override;
|
2021-03-25 14:07:16 +00:00
|
|
|
|
|
|
|
protected:
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I m_position; // Position of the pin.
|
2021-03-25 14:07:16 +00:00
|
|
|
int m_length; // Length of the pin.
|
|
|
|
int m_orientation; // Pin orientation (Up, Down, Left, Right)
|
|
|
|
GRAPHIC_PINSHAPE m_shape; // Shape drawn around pin
|
|
|
|
ELECTRICAL_PINTYPE m_type; // Electrical type of the pin.
|
|
|
|
int m_attributes; // Set bit 0 to indicate pin is invisible.
|
|
|
|
wxString m_name;
|
|
|
|
wxString m_number;
|
|
|
|
int m_numTextSize; // Pin num and Pin name sizes
|
|
|
|
int m_nameTextSize;
|
|
|
|
|
|
|
|
std::map<wxString, ALT> m_alternates; // Map of alternate name to ALT structure
|
2023-02-09 17:18:56 +00:00
|
|
|
|
|
|
|
wxString m_operatingPoint; // No, LIB_PINs don't really have operating points.
|
|
|
|
// But we draw SCH_PINs through their LIB_PIN
|
|
|
|
// counterparts, so here we are....
|
2010-03-04 09:32:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CLASS_PIN_H
|