Fix crash when attempting to tune discontinuous lines

Also correctly find the tuning path through arcs

https://gitlab.com/kicad/code/kicad/-/issues/8131
This commit is contained in:
Jon Evans 2021-04-06 09:07:00 -04:00
parent 235688e459
commit 9f957d3e08
1 changed files with 39 additions and 37 deletions

View File

@ -250,22 +250,29 @@ const ITEM_SET TOPOLOGY::AssembleTrivialPath( ITEM* aStart,
{
ITEM_SET path;
std::set<ITEM*> visited;
SEGMENT* seg;
VIA* via;
LINKED_ITEM* seg = nullptr;
seg = dyn_cast<SEGMENT*>( aStart );
if(!seg && (via = dyn_cast<VIA*>( aStart ) ) )
if( aStart->Kind() == ITEM::VIA_T )
{
JOINT *jt = m_world->FindJoint( via->Pos(), via );
VIA* via = static_cast<VIA*>( aStart );
JOINT* jt = m_world->FindJoint( via->Pos(), via );
if( !jt->IsNonFanoutVia() )
return ITEM_SET();
for( const auto& entry : jt->Links().Items() )
if( ( seg = dyn_cast<SEGMENT*>( entry.item ) ) )
for( const ITEM_SET::ENTRY& entry : jt->Links().Items() )
{
if( entry.item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
{
seg = static_cast<LINKED_ITEM*>( entry.item );
break;
}
}
}
else if( aStart->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
{
seg = static_cast<LINKED_ITEM*>( aStart );
}
if( !seg )
return ITEM_SET();
@ -298,7 +305,10 @@ const ITEM_SET TOPOLOGY::AssembleTuningPath( ITEM* aStart, SOLID** aStartPad, SO
PAD* padA = nullptr;
PAD* padB = nullptr;
for( ITEM* item : joints.first->LinkList() )
auto getPadFromJoint =
[]( JOINT* aJoint, PAD** aTargetPad, SOLID** aTargetSolid )
{
for( ITEM* item : aJoint->LinkList() )
{
if( item->OfKind( ITEM::SOLID_T ) )
{
@ -306,33 +316,25 @@ const ITEM_SET TOPOLOGY::AssembleTuningPath( ITEM* aStart, SOLID** aStartPad, SO
if( bi->Type() == PCB_PAD_T )
{
padA = static_cast<PAD*>( bi );
*aTargetPad = static_cast<PAD*>( bi );
if( aStartPad )
*aStartPad = static_cast<SOLID*>( item );
if( aTargetSolid )
*aTargetSolid = static_cast<SOLID*>( item );
}
break;
}
}
};
for( ITEM* item : joints.second->LinkList() )
{
if( item->OfKind( ITEM::SOLID_T ) )
{
BOARD_ITEM* bi = static_cast<SOLID*>( item )->Parent();
if( joints.first )
getPadFromJoint( joints.first, &padA, aStartPad );
if( bi->Type() == PCB_PAD_T )
{
padB = static_cast<PAD*>( bi );
if( joints.second )
getPadFromJoint( joints.second, &padB, aEndPad );
if( aEndPad )
*aEndPad = static_cast<SOLID*>( item );
}
break;
}
}
if( !padA && !padB )
return initialPath;
auto clipLineToPad =
[]( SHAPE_LINE_CHAIN& aLine, PAD* aPad, bool aForward = true )