Fix layer translation in setting start item

Need to be very careful when translating between PNS layers and board
layers.  PNS layers are linear while board layers are not, so reaching
into the view will return a board layer (maybe we should proxy this
through the iface?)

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18708
This commit is contained in:
Seth Hillbrand 2024-09-27 11:06:35 -07:00
parent d8f71e6754
commit a8dc101010
5 changed files with 14 additions and 3 deletions

View File

@ -1436,6 +1436,11 @@ void PNS_KICAD_IFACE_BASE::SetBoard( BOARD* aBoard )
wxLogTrace( wxT( "PNS" ), wxT( "m_board = %p" ), m_board );
}
bool PNS_KICAD_IFACE_BASE::IsCopperLayer( int aLayer ) const
{
return ::IsCopperLayer( GetBoardLayerFromPNSLayer( aLayer ) );
}
bool PNS_KICAD_IFACE::IsAnyLayerVisible( const PNS_LAYER_RANGE& aLayer ) const
{

View File

@ -61,6 +61,7 @@ public:
bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const override;
bool IsFlashedOnLayer( const PNS::ITEM* aItem, const PNS_LAYER_RANGE& aLayer ) const override;
bool IsItemVisible( const PNS::ITEM* aItem ) const override { return true; };
bool IsCopperLayer( int aLayer ) const override;
void HideItem( PNS::ITEM* aItem ) override {}
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
int aFlags = 0 ) override {}

View File

@ -97,6 +97,7 @@ enum DRAG_MODE
virtual bool IsItemVisible( const PNS::ITEM* aItem ) const = 0;
virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const = 0;
virtual bool IsFlashedOnLayer( const PNS::ITEM* aItem, const PNS_LAYER_RANGE& aLayer ) const = 0;
virtual bool IsCopperLayer( int aLayer ) const = 0;
virtual void DisplayItem( const ITEM* aItem, int aClearance, bool aEdit = false,
int aFlags = 0 ) = 0;
virtual void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) = 0;

View File

@ -110,7 +110,9 @@ void TOOL_BASE::Reset( RESET_REASON aReason )
ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, NET_HANDLE aNet, int aLayer,
bool aIgnorePads, const std::vector<ITEM*> aAvoidItems )
{
int tl = aLayer > 0 ? aLayer : getView()->GetTopLayer();
int tl = aLayer > 0 ? aLayer
: m_router->GetInterface()->GetPNSLayerFromBoardLayer(
static_cast<PCB_LAYER_ID>( getView()->GetTopLayer() ) );
int maxSlopRadius = std::max( m_gridHelper->GetGrid().x, m_gridHelper->GetGrid().y );
static const int candidateCount = 5;
@ -144,7 +146,7 @@ ITEM* TOOL_BASE::pickSingleItem( const VECTOR2I& aWhere, NET_HANDLE aNet, int aL
if( !item->IsRoutable() )
continue;
if( !IsCopperLayer( item->Layers().Start() ) )
if( !m_iface->IsCopperLayer( item->Layers().Start() ) )
continue;
if( !m_iface->IsAnyLayerVisible( item->Layers() ) )
@ -328,7 +330,8 @@ bool TOOL_BASE::checkSnap( ITEM *aItem )
void TOOL_BASE::updateStartItem( const TOOL_EVENT& aEvent, bool aIgnorePads )
{
int tl = getView()->GetTopLayer();
int tl = m_router->GetInterface()->GetPNSLayerFromBoardLayer(
static_cast<PCB_LAYER_ID>( getView()->GetTopLayer() ) );
GAL* gal = m_toolMgr->GetView()->GetGAL();
VECTOR2I pos = aEvent.HasPosition() ? (VECTOR2I) aEvent.Position() : m_startSnapPoint;

View File

@ -59,6 +59,7 @@ public:
bool IsFlashedOnLayer( const PNS::ITEM* aItem, int aLayer ) const override { return false; };
bool IsFlashedOnLayer( const PNS::ITEM* aItem, const PNS_LAYER_RANGE& aLayer ) const override { return false; };
bool IsItemVisible( const PNS::ITEM* aItem ) const override { return true; };
bool IsCopperLayer( int aLayer ) const override { return false; };
void HideItem( PNS::ITEM* aItem ) override {}
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
int aFlags = 0 ) override {}