Add PNS::ITEM::BoardItem() call.

About 1/3 of callers to Parent() don't care if they get the immediate
parent or not, about 1/3 want only the immediate parent, and about 1/3
want the hole parent's Parent().

I had earlier changed PNS::ITEM::HOLE to override Parent() and return
the hole parent's Parent(), but since the callers are pretty evenly
split I've reverted that and added BoardItem() for callers who want the
eventual BOARD_ITEM (whether a direct parent or a grandparent).

(Also removes a dead routine so I didn't have to figure out which of
the two it wanted....)

(cherry picked from commit 6f0d963683)
This commit is contained in:
Jeff Young 2023-04-06 17:59:43 +01:00
parent 4c04233a20
commit 3b05d03220
8 changed files with 20 additions and 38 deletions

View File

@ -61,7 +61,7 @@ public:
ITEM* ParentPadVia() const { return m_parentPadVia; }
BOARD_ITEM* Parent() const override
BOARD_ITEM* BoardItem() const override
{
if( m_parent )
return m_parent;

View File

@ -165,7 +165,7 @@ public:
}
/**
* Return true if the item's type matches the mask \a aKindMask.
* @return true if the item's type matches the mask \a aKindMask.
*/
bool OfKind( int aKindMask ) const
{
@ -173,12 +173,17 @@ public:
}
/**
* Returns the kind of the item, as string
* @return the kind of the item, as string
*/
std::string KindStr() const;
void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
virtual BOARD_ITEM* Parent() const { return m_parent; }
BOARD_ITEM* Parent() const { return m_parent; }
/**
* @return the BOARD_ITEM, even if it's not the direct parent.
*/
virtual BOARD_ITEM* BoardItem() const { return m_parent; }
void SetNet( int aNet ) { m_net = aNet; }
int Net() const { return m_net; }

View File

@ -110,7 +110,6 @@ public:
virtual int DpCoupledNet( int aNet ) override;
virtual int DpNetPolarity( int aNet ) override;
virtual bool DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN ) override;
virtual bool IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
virtual bool IsInNetTie( const PNS::ITEM* aA ) override;
virtual bool IsNetTieExclusion( const PNS::ITEM* aItem, const VECTOR2I& aCollisionPos,
@ -172,26 +171,10 @@ PNS_PCBNEW_RULE_RESOLVER::~PNS_PCBNEW_RULE_RESOLVER()
}
bool PNS_PCBNEW_RULE_RESOLVER::IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* aB )
{
int net_p, net_n;
if( !DpNetPair( aA, net_p, net_n ) )
return false;
if( aA->Net() == net_p && aB->Net() == net_n )
return true;
if( aB->Net() == net_p && aA->Net() == net_n )
return true;
return false;
}
bool PNS_PCBNEW_RULE_RESOLVER::IsInNetTie( const PNS::ITEM* aA )
{
BOARD_ITEM* item = aA->Parent();
BOARD_ITEM* item = aA->BoardItem();
BOARD_ITEM* parentFootprint = item ? item->GetParentFootprint() : nullptr;
if( parentFootprint )
@ -208,7 +191,8 @@ bool PNS_PCBNEW_RULE_RESOLVER::IsNetTieExclusion( const PNS::ITEM* aItem,
wxCHECK( aItem && aCollidingItem, false );
std::shared_ptr<DRC_ENGINE> drcEngine = m_board->GetDesignSettings().m_DRCEngine;
BOARD_ITEM* collidingItem = aCollidingItem->Parent();
BOARD_ITEM* item = aItem->BoardItem();
BOARD_ITEM* collidingItem = aCollidingItem->BoardItem();
FOOTPRINT* collidingFp = static_cast<FOOTPRINT*>( collidingItem->GetParentFootprint() );
FOOTPRINT* itemFp = aItem->Parent()
@ -296,7 +280,7 @@ static bool isEdge( const PNS::ITEM* aItem )
if ( !aItem )
return false;
const BOARD_ITEM *parent = aItem->Parent();
const BOARD_ITEM *parent = aItem->BoardItem();
return parent && ( parent->IsOnLayer( Edge_Cuts ) || parent->IsOnLayer( Margin ) );
}
@ -327,8 +311,8 @@ bool PNS_PCBNEW_RULE_RESOLVER::QueryConstraint( PNS::CONSTRAINT_TYPE aType,
default: return false; // should not happen
}
BOARD_ITEM* parentA = aItemA ? aItemA->Parent() : nullptr;
BOARD_ITEM* parentB = aItemB ? aItemB->Parent() : nullptr;
BOARD_ITEM* parentA = aItemA ? aItemA->BoardItem() : nullptr;
BOARD_ITEM* parentB = aItemB ? aItemB->BoardItem() : nullptr;
DRC_CONSTRAINT hostConstraint;
// A track being routed may not have a BOARD_ITEM associated yet.
@ -1408,7 +1392,7 @@ bool PNS_KICAD_IFACE_BASE::IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer
if( aLayer < 0 )
return true;
if( !aItem->OfKind( PNS::ITEM::HOLE_T ) && aItem->Parent() )
if( aItem->Parent() )
{
switch( aItem->Parent()->Type() )
{

View File

@ -1579,9 +1579,6 @@ ITEM *NODE::FindItemByParent( const BOARD_ITEM* aParent )
{
for( ITEM* item : *l_cur )
{
if( item->OfKind( PNS::ITEM::HOLE_T ) && static_cast<HOLE*>( item )->ParentPadVia() )
continue;
if( item->Parent() == aParent )
return item;
}

View File

@ -142,8 +142,6 @@ public:
virtual int DpNetPolarity( int aNet ) = 0;
virtual bool DpNetPair( const ITEM* aItem, int& aNetP, int& aNetN ) = 0;
virtual bool IsDiffPair( const ITEM* aA, const ITEM* aB ) = 0;
virtual bool IsInNetTie( const ITEM* aA ) = 0;
virtual bool IsNetTieExclusion( const PNS::ITEM* aItem, const VECTOR2I& aCollisionPos,
const PNS::ITEM* aCollidingItem )= 0;

View File

@ -250,7 +250,7 @@ bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aStartItem,
for( ITEM* item : candidates.Items() )
{
// Edge cuts are put on all layers, but they're not *really* on all layers
if( item->Parent() && item->Parent()->GetLayer() == Edge_Cuts )
if( item->BoardItem() && item->BoardItem()->GetLayer() == Edge_Cuts )
continue;
if( !item->Layers().Overlaps( aLayer ) )
@ -263,7 +263,7 @@ bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aStartItem,
}
else
{
BOARD_ITEM* parent = item->Parent();
BOARD_ITEM* parent = item->BoardItem();
switch( parent->Type() )
{

View File

@ -43,7 +43,7 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
m_shape( nullptr ),
m_hole( nullptr )
{
BOARD_ITEM* boardItem = aItem ? aItem->Parent() : nullptr;
BOARD_ITEM* boardItem = aItem ? aItem->BoardItem() : nullptr;
// A PNS::SOLID for an edge-cut item must have 0 width for collision calculations, but when
// highlighting an edge we want to show it with its parent PCB_SHAPE's shape.

View File

@ -138,8 +138,6 @@ public:
{
return false;
}
virtual bool IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* aB ) override { return false; }
virtual bool QueryConstraint( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA,
const PNS::ITEM* aItemB, int aLayer,
PNS::CONSTRAINT* aConstraint ) override