Remove pins from symbol hit-testing.

Fixes https://gitlab.com/kicad/code/kicad/issues/8508
This commit is contained in:
Jeff Young 2021-09-23 22:07:19 +01:00
parent b065ff33dc
commit 552f053a55
9 changed files with 55 additions and 51 deletions

View File

@ -129,7 +129,7 @@ public:
m_align_to_grid = cfg->m_AutoplaceFields.align_to_grid;
}
m_symbol_bbox = m_symbol->GetBodyBoundingBox();
m_symbol_bbox = m_symbol->GetBodyAndPinsBoundingBox();
m_fbox_size = computeFBoxSize( /* aDynamic */ true );
m_is_power_symbol = !m_symbol->IsInNetlist();
@ -294,7 +294,7 @@ protected:
EDA_RECT item_box;
if( SCH_SYMBOL* item_comp = dynamic_cast<SCH_SYMBOL*>( item ) )
item_box = item_comp->GetBodyBoundingBox();
item_box = item_comp->GetBodyAndPinsBoundingBox();
else
item_box = item->GetBoundingBox();

View File

@ -144,8 +144,7 @@ SCH_ITEM* SCH_EDITOR_CONTROL::FindSymbolAndItem( const wxString& aReference,
#endif // COMP_1_TO_1_RATIO
#ifndef COMP_1_TO_1_RATIO // Do the scaled zoom
// Pass "false" to only include visible fields of symbol in bbox calculations.
EDA_RECT bbox = symbol->GetBoundingBox( false );
EDA_RECT bbox = symbol->GetBoundingBox();
wxSize bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
VECTOR2D screenSize = getView()->GetViewport().GetSize();

View File

@ -848,7 +848,7 @@ void LIB_SYMBOL::ViewGetLayers( int aLayers[], int& aCount ) const
}
const EDA_RECT LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert ) const
const EDA_RECT LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert, bool aIncludePins ) const
{
EDA_RECT bbox;
@ -864,9 +864,17 @@ const EDA_RECT LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert ) const
continue;
if( item.Type() == LIB_PIN_T )
bbox.Merge( static_cast<const LIB_PIN&>( item ).GetBoundingBox( false, true ) );
{
if( aIncludePins )
{
const LIB_PIN& pin = static_cast<const LIB_PIN&>( item );
bbox.Merge( pin.GetBoundingBox( false, true ) );
}
}
else
{
bbox.Merge( item.GetBoundingBox() );
}
}
return bbox;

View File

@ -215,7 +215,7 @@ public:
* if aConvert == 0 Convert is non used
* Fields are not taken in account
**/
const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert, bool aIncludePins ) const;
const EDA_RECT GetBoundingBox() const override
{

View File

@ -1500,16 +1500,8 @@ const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
for( EDA_ITEM* item : GetScreen()->Items() )
{
if( item != dsAsItem ) // Ignore the drawing-sheet itself
{
if( item->Type() == SCH_SYMBOL_T )
{
// For symbols we need to get the bounding box without invisible text
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
bBoxItems.Merge( symbol->GetBoundingBox( false ) );
}
else
bBoxItems.Merge( item->GetBoundingBox() );
}
bBoxItems.Merge( item->GetBoundingBox() );
bBoxDoc = bBoxItems;
}
}

View File

@ -166,7 +166,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSh
if( item->Type() == SCH_SYMBOL_T )
{
SCH_SYMBOL* comp = static_cast<SCH_SYMBOL*>( item );
bbox = comp->GetBodyBoundingBox();
bbox = comp->GetBodyAndPinsBoundingBox();
for( const SCH_FIELD& field : comp->GetFields() )
{

View File

@ -1298,14 +1298,14 @@ void SCH_SYMBOL::Show( int nestLevel, std::ostream& os ) const
#endif
EDA_RECT SCH_SYMBOL::GetBodyBoundingBox() const
EDA_RECT SCH_SYMBOL::doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) const
{
EDA_RECT bBox;
if( m_part )
bBox = m_part->GetBodyBoundingBox( m_unit, m_convert );
bBox = m_part->GetBodyBoundingBox( m_unit, m_convert, aIncludePins );
else
bBox = dummy()->GetBodyBoundingBox( m_unit, m_convert );
bBox = dummy()->GetBodyBoundingBox( m_unit, m_convert, aIncludePins );
int x0 = bBox.GetX();
int xm = bBox.GetRight();
@ -1329,35 +1329,35 @@ EDA_RECT SCH_SYMBOL::GetBodyBoundingBox() const
bBox.Normalize();
bBox.Offset( m_pos );
if( aIncludeFields )
{
for( const SCH_FIELD& field : m_fields )
{
if( field.IsVisible() )
bBox.Merge( field.GetBoundingBox() );
}
}
return bBox;
}
EDA_RECT SCH_SYMBOL::GetBodyBoundingBox() const
{
return doGetBoundingBox( false, false );
}
EDA_RECT SCH_SYMBOL::GetBodyAndPinsBoundingBox() const
{
return doGetBoundingBox( true, false );
}
const EDA_RECT SCH_SYMBOL::GetBoundingBox() const
{
EDA_RECT bbox = GetBodyBoundingBox();
for( const SCH_FIELD& field : m_fields )
{
if( field.IsVisible() )
bbox.Merge( field.GetBoundingBox() );
}
return bbox;
}
const EDA_RECT SCH_SYMBOL::GetBoundingBox( bool aIncludeInvisibleText ) const
{
EDA_RECT bbox = GetBodyBoundingBox();
for( const SCH_FIELD& field : m_fields )
{
if( field.IsVisible() || aIncludeInvisibleText )
bbox.Merge( field.GetBoundingBox() );
}
return bbox;
return doGetBoundingBox( true, true );
}
@ -1716,10 +1716,10 @@ bool SCH_SYMBOL::operator <( const SCH_ITEM& aItem ) const
auto symbol = static_cast<const SCH_SYMBOL*>( &aItem );
EDA_RECT rect = GetBodyBoundingBox();
EDA_RECT rect = GetBodyAndPinsBoundingBox();
if( rect.GetArea() != symbol->GetBodyBoundingBox().GetArea() )
return rect.GetArea() < symbol->GetBodyBoundingBox().GetArea();
if( rect.GetArea() != symbol->GetBodyAndPinsBoundingBox().GetArea() )
return rect.GetArea() < symbol->GetBodyAndPinsBoundingBox().GetArea();
if( m_pos.x != symbol->m_pos.x )
return m_pos.x < symbol->m_pos.x;

View File

@ -315,13 +315,16 @@ public:
const EDA_RECT GetBoundingBox() const override;
const EDA_RECT GetBoundingBox( bool aIncludeInvisibleText ) const;
/**
* Return a bounding box for the symbol body but not the fields.
* Return a bounding box for the symbol body but not the pins or fields.
*/
EDA_RECT GetBodyBoundingBox() const;
/**
* Return a bounding box for the symbol body and pins but not the fields.
*/
EDA_RECT GetBodyAndPinsBoundingBox() const;
//-----<Fields>-----------------------------------------------------------
@ -665,6 +668,8 @@ public:
bool IsPointClickableAnchor( const wxPoint& aPos ) const override;
private:
EDA_RECT doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) const;
bool doIsConnected( const wxPoint& aPosition ) const override;
void Init( const wxPoint& pos = wxPoint( 0, 0 ) );

View File

@ -73,7 +73,7 @@ EDA_RECT EE_SELECTION::GetBoundingBox() const
// so the exception is legit.
try
{
bbox.Merge( static_cast<SCH_SYMBOL*>( item )->GetBoundingBox( false ) );
bbox.Merge( static_cast<SCH_SYMBOL*>( item )->GetBoundingBox() );
}
catch( const boost::bad_pointer& exc )
{