7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Include dangling indicator in SCH_PIN bbox

Delegate computation of the size and location of the pin dangling
indicator to the PIN_LAYOUT_CACHE.

Relates-To: https://gitlab.com/kicad/code/kicad/-/issues/18894
This commit is contained in:
John Beard 2024-10-11 09:07:42 +08:00
parent fe48e51315
commit f29d1fafe4
6 changed files with 62 additions and 18 deletions

View File

@ -234,8 +234,30 @@ BOX2I PIN_LAYOUT_CACHE::GetPinBoundingBox( bool aIncludeLabelsOnInvisiblePins,
BOX2I bbox = BOX2I::ByCorners( begin, end );
bbox.Move( m_pin.GetPosition() );
if( m_pin.IsDangling() )
{
// Not much point caching this
const CIRCLE c = GetDanglingIndicator();
BOX2I cBox = BOX2I::ByCenter( c.Center, { c.Radius * 2, c.Radius * 2 } );
// TODO: need some way to find the thickness...?
// cBox.Inflate( ??? );
bbox.Merge( cBox );
}
bbox.Normalize();
bbox.Inflate( ( m_pin.GetPenWidth() / 2 ) + 1 );
return bbox;
}
CIRCLE PIN_LAYOUT_CACHE::GetDanglingIndicator() const
{
return CIRCLE{
m_pin.GetPosition(),
TARGET_PIN_RADIUS,
};
}

View File

@ -23,7 +23,10 @@
#pragma once
#include <optional>
#include <geometry/circle.h>
#include <geometry/seg.h>
#include <math/box2.h>
#include <sch_pin.h>
@ -66,6 +69,12 @@ public:
BOX2I GetPinBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
bool aIncludeElectricalType );
/**
* Gets the dangling indicator geometry for this pin, if the
* pin were to be dangling.
*/
CIRCLE GetDanglingIndicator() const;
private:
bool isDirty( int aMask ) const

View File

@ -36,6 +36,7 @@
#include <gr_text.h>
#include <sch_pin.h>
#include <math/util.h>
#include <pin_layout_cache.h>
#include <pgm_base.h>
#include <sch_bitmap.h>
#include <sch_bus_entry.h>
@ -777,19 +778,23 @@ int SCH_PAINTER::externalPinDecoSize( const SCH_PIN &aPin )
// Draw the target (an open circle) for a pin which has no connection or is being moved.
void SCH_PAINTER::drawPinDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor,
void SCH_PAINTER::drawPinDanglingIndicator( const SCH_PIN& aPin, const COLOR4D& aColor,
bool aDrawingShadows, bool aBrightened )
{
const PIN_LAYOUT_CACHE& plc = aPin.GetLayoutCache();
const CIRCLE c = plc.GetDanglingIndicator();
float lineWidth = aDrawingShadows ? getShadowWidth( aBrightened )
: m_schSettings.GetDanglingIndicatorThickness();
// Dangling symbols must be drawn in a slightly different colour so they can be seen when
// they overlap with a junction dot.
m_gal->SetStrokeColor( aColor.Brightened( 0.3 ) );
m_gal->SetIsFill( false );
m_gal->SetIsStroke( true );
m_gal->SetLineWidth( aDrawingShadows ? getShadowWidth( aBrightened )
: m_schSettings.GetDanglingIndicatorThickness() );
m_gal->DrawCircle( aPos, TARGET_PIN_RADIUS );
m_gal->SetLineWidth( lineWidth );
m_gal->DrawCircle( c.Center, c.Radius );
}
@ -1226,7 +1231,7 @@ void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed )
else
{
if( drawingDangling && isDangling && aPin->IsGlobalPower() )
drawPinDanglingIndicator( pos, color, drawingShadows, aPin->IsBrightened() );
drawPinDanglingIndicator( *aPin, color, drawingShadows, aPin->IsBrightened() );
return;
}
@ -1235,7 +1240,7 @@ void SCH_PAINTER::draw( const SCH_PIN* aPin, int aLayer, bool aDimmed )
if( drawingDangling )
{
if( isDangling )
drawPinDanglingIndicator( pos, color, drawingShadows, aPin->IsBrightened() );
drawPinDanglingIndicator( *aPin, color, drawingShadows, aPin->IsBrightened() );
return;
}

View File

@ -101,8 +101,8 @@ private:
void draw( const SCH_LINE* aLine, int aLayer );
void draw( const SCH_BUS_ENTRY_BASE* aEntry, int aLayer );
void drawPinDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor,
bool aDrawingShadows, bool aBrightened );
void drawPinDanglingIndicator( const SCH_PIN& aPin, const COLOR4D& aColor, bool aDrawingShadows,
bool aBrightened );
void drawDanglingIndicator( const VECTOR2I& aPos, const COLOR4D& aColor, int aWidth,
bool aDangling, bool aDrawingShadows, bool aBrightened );
void drawAnchor( const VECTOR2I& aPos, bool aDrawingShadows );

View File

@ -394,6 +394,21 @@ void SCH_PIN::SetName( const wxString& aName )
}
bool SCH_PIN::IsDangling() const
{
if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
return false;
return m_isDangling;
}
void SCH_PIN::SetIsDangling( bool aIsDangling )
{
m_isDangling = aIsDangling;
}
bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
{
bool isConnectableType_a = GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE

View File

@ -269,15 +269,8 @@ public:
void ClearDefaultNetName( const SCH_SHEET_PATH* aPath );
wxString GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect = false );
bool IsDangling() const override
{
if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
return false;
return m_isDangling;
}
void SetIsDangling( bool isDangling ) { m_isDangling = isDangling; }
bool IsDangling() const override;
void SetIsDangling( bool aIsDangling );
/**
* @param aPin Comparison Pin