From a1a2076aee55c9d1bf27bdb0038b0df0d324b16a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 24 Sep 2021 16:19:21 +0100 Subject: [PATCH] Include pin roots for symbols that don't have well-defined bodies. Fixes https://gitlab.com/kicad/code/kicad/issues/8508 --- eeschema/lib_pin.cpp | 13 +++++++++++++ eeschema/lib_pin.h | 2 ++ eeschema/lib_symbol.cpp | 10 +++++++--- eeschema/sch_painter.cpp | 32 ++++++++------------------------ 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index 50f98c45df..d166c5f949 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -178,6 +178,19 @@ wxString LIB_PIN::GetShownName() const } +wxPoint LIB_PIN::GetPinRoot() const +{ + switch( m_orientation ) + { + default: + case PIN_RIGHT: return wxPoint( m_position.x + m_length, m_position.y ); + case PIN_LEFT: return wxPoint( m_position.x - m_length, m_position.y ); + case PIN_UP: return wxPoint( m_position.x, m_position.y - m_length ); + case PIN_DOWN: return wxPoint( m_position.x, m_position.y + m_length ); + } +} + + void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData, const TRANSFORM& aTransform ) { diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index d191041d4d..77585c2efb 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -210,6 +210,8 @@ public: wxPoint GetPosition() const override { return m_position; } void SetPosition( const wxPoint& aPos ) override { m_position = aPos; } + wxPoint GetPinRoot() const; + void MirrorHorizontal( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override; void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override; diff --git a/eeschema/lib_symbol.cpp b/eeschema/lib_symbol.cpp index 8732870851..b6ad4c6d6a 100644 --- a/eeschema/lib_symbol.cpp +++ b/eeschema/lib_symbol.cpp @@ -865,11 +865,15 @@ const EDA_RECT LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert, bool aIn if( item.Type() == LIB_PIN_T ) { + const LIB_PIN& pin = static_cast( item ); + + // Note: the roots of the pins are always inlcuded for symbols that don't have a + // well-defined body. + if( aIncludePins ) - { - const LIB_PIN& pin = static_cast( item ); bbox.Merge( pin.GetBoundingBox( false, true ) ); - } + else + bbox.Merge( pin.GetPinRoot() ); } else { diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 812d7d0637..86f4c3c928 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -810,33 +810,17 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer ) } } - VECTOR2I p0; + VECTOR2I p0( aPin->GetPinRoot() ); VECTOR2I dir; - int len = aPin->GetLength(); - int orient = aPin->GetOrientation(); + int len = aPin->GetLength(); - switch( orient ) + switch( aPin->GetOrientation() ) { - case PIN_UP: - p0 = VECTOR2I( pos.x, pos.y - len ); - dir = VECTOR2I( 0, 1 ); - break; - - case PIN_DOWN: - p0 = VECTOR2I( pos.x, pos.y + len ); - dir = VECTOR2I( 0, -1 ); - break; - - case PIN_LEFT: - p0 = VECTOR2I( pos.x - len, pos.y ); - dir = VECTOR2I( 1, 0 ); - break; - default: - case PIN_RIGHT: - p0 = VECTOR2I( pos.x + len, pos.y ); - dir = VECTOR2I( -1, 0 ); - break; + case PIN_RIGHT: dir = VECTOR2I( -1, 0 ); break; + case PIN_LEFT: dir = VECTOR2I( 1, 0 ); break; + case PIN_UP: dir = VECTOR2I( 0, 1 ); break; + case PIN_DOWN: dir = VECTOR2I( 0, -1 ); break; } VECTOR2D pc; @@ -1088,7 +1072,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer ) strokeText( aText, aPos, aAngle ); }; - switch( orient ) + switch( aPin->GetOrientation() ) { case PIN_LEFT: if( size[INSIDE] )