Use a more self-documenting API for router preview item flags.

Also fixes a bug where rule areas were drawn with solid fills.
This commit is contained in:
Jeff Young 2023-12-08 16:01:27 +00:00
parent 096bcff160
commit e0a34efcb7
10 changed files with 52 additions and 42 deletions

View File

@ -1860,7 +1860,7 @@ std::vector<EDA_ITEM*> PCB_TUNING_PATTERN::GetPreviewItems( GENERATOR_TOOL* aToo
PNS::ITEM_SET items = placer->TunedPath();
for( PNS::ITEM* item : items )
previewItems.push_back( new ROUTER_PREVIEW_ITEM( item, view, true ) );
previewItems.push_back( new ROUTER_PREVIEW_ITEM( item, view, PNS_HOVER_ITEM ) );
}
TUNING_STATUS_VIEW_ITEM* statusItem = new TUNING_STATUS_VIEW_ITEM( aFrame );

View File

@ -1626,12 +1626,18 @@ void PNS_KICAD_IFACE_BASE::SetDebugDecorator( PNS::DEBUG_DECORATOR *aDec )
}
void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit, bool aIsHeadTrace )
void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit, int aFlags )
{
if( aItem->IsVirtual() )
return;
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view );
if( ZONE* zone = dynamic_cast<ZONE*>( aItem->Parent() ) )
{
if( zone->GetIsRuleArea() )
aFlags |= PNS_SEMI_SOLID;
}
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view, aFlags );
// Note: SEGMENT_T is used for placed tracks; LINE_T is used for the routing head
static int tracks = PNS::ITEM::SEGMENT_T | PNS::ITEM::ARC_T | PNS::ITEM::LINE_T;
@ -1664,12 +1670,6 @@ void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool
}
}
if( aIsHeadTrace )
{
pitem->SetIsHeadTrace( true );
pitem->Update( aItem );
}
m_previewItems->Add( pitem );
m_view->Update( m_previewItems );
}

View File

@ -63,7 +63,7 @@ public:
bool IsItemVisible( const PNS::ITEM* aItem ) const override { return true; };
void HideItem( PNS::ITEM* aItem ) override {}
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
bool aIsHeadTrace = false ) override {}
int aFlags = 0 ) override {}
void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) override {}
void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, PNS::NET_HANDLE aNet ) override {}
void AddItem( PNS::ITEM* aItem ) override;
@ -124,7 +124,8 @@ public:
bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) const override;
bool IsItemVisible( const PNS::ITEM* aItem ) const override;
void HideItem( PNS::ITEM* aItem ) override;
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false, bool aIsHeadTrace = false ) override;
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
int aFlags = 0 ) override;
void DisplayPathLine( const SHAPE_LINE_CHAIN& aLine, int aImportance ) override;
void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, PNS::NET_HANDLE aNet ) override;
void Commit() override;

View File

@ -23,15 +23,12 @@
#include <memory>
#include <vector>
#include <view/view.h>
#include <view/view_group.h>
#include <gal/graphics_abstraction_layer.h>
#include <advanced_config.h>
#include <settings/settings_manager.h>
#include <pcb_painter.h>
#include <pcbnew_settings.h>
#include <pad.h>
#include <zone.h>
@ -51,6 +48,7 @@
#include "pns_meander_placer.h"
#include "pns_meander_skew_placer.h"
#include "pns_dp_meander_placer.h"
#include "router_preview_item.h"
namespace PNS {
@ -757,7 +755,7 @@ bool ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem )
const LINE* l = static_cast<const LINE*>( item );
int clearance = GetRuleResolver()->Clearance( item, nullptr );
m_iface->DisplayItem( l, clearance, false, true );
m_iface->DisplayItem( l, clearance, false, PNS_HEAD_TRACE );
if( l->EndsWithVia() )
{
@ -774,7 +772,7 @@ bool ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem )
clearance = excessHoleClearance;
}
m_iface->DisplayItem( &l->Via(), clearance, false, true );
m_iface->DisplayItem( &l->Via(), clearance, false, PNS_HEAD_TRACE );
}
}

View File

@ -97,7 +97,8 @@ 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 LAYER_RANGE& aLayer ) const = 0;
virtual void DisplayItem( const ITEM* aItem, int aClearance, bool aEdit = false, bool aIsHeadTrace = false ) = 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;
virtual void DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, NET_HANDLE aNetCode ) = 0;
virtual void HideItem( ITEM* aItem ) = 0;

View File

@ -38,13 +38,12 @@
using namespace KIGFX;
ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* aView,
bool aIsHoverItem ) :
EDA_ITEM( NOT_USED ),
m_view( aView ),
m_shape( nullptr ),
m_hole( nullptr ),
m_isHoverItem( aIsHoverItem )
ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* aView, int aFlags ) :
EDA_ITEM( NOT_USED ),
m_view( aView ),
m_shape( nullptr ),
m_hole( nullptr ),
m_flags( aFlags )
{
BOARD_ITEM* boardItem = aItem ? aItem->BoardItem() : nullptr;
@ -69,9 +68,8 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
// initialize variables, overwritten by Update( aItem ), if aItem != NULL
m_type = PR_SHAPE;
m_width = 0;
m_width = ( aFlags & PNS_SEMI_SOLID ) ? 1 : 0;
m_depth = 0;
m_isHeadTrace = false;
if( aItem )
Update( aItem );
@ -79,7 +77,8 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const SHAPE& aShape, KIGFX::VIEW* aView ) :
EDA_ITEM( NOT_USED )
EDA_ITEM( NOT_USED ),
m_flags( 0 )
{
m_view = aView;
@ -95,8 +94,6 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const SHAPE& aShape, KIGFX::VIEW* aVie
m_type = PR_SHAPE;
m_width = 0;
m_depth = 0;
m_isHeadTrace = false;
m_isHoverItem = false;
}
@ -169,17 +166,21 @@ void ROUTER_PREVIEW_ITEM::Update( const PNS::ITEM* aItem )
case PNS::ITEM::SOLID_T:
m_type = PR_SHAPE;
m_width = 0;
break;
default:
break;
}
m_flags &= ~PNS_COLLISION;
if( aItem->Marker() & PNS::MK_VIOLATION )
m_flags |= PNS_COLLISION;
if( m_flags & PNS_COLLISION )
m_color = COLOR4D( 0, 1, 0, 1 );
if( m_isHoverItem )
if( m_flags & PNS_HOVER_ITEM )
m_color = m_color.WithAlpha( 1.0 );
}
@ -484,6 +485,10 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
gal->SetIsStroke( m_width ? true : false );
gal->SetIsFill( true );
// Semi-solids (ie: rule areas) which are not in collision are sketched (ie: outline only)
if( ( m_flags & PNS_SEMI_SOLID ) > 0 && ( m_flags & PNS_COLLISION ) == 0 )
gal->SetIsFill( false );
if( m_shape->HasIndexableSubshapes() )
{
std::vector<const SHAPE*> subshapes;
@ -506,9 +511,9 @@ const COLOR4D ROUTER_PREVIEW_ITEM::getLayerColor( int aLayer ) const
COLOR4D color = settings->GetLayerColor( aLayer );
if( m_isHeadTrace )
if( m_flags & PNS_HEAD_TRACE )
return color.Saturate( 1.0 );
else if( m_isHoverItem )
else if( m_flags & PNS_HOVER_ITEM )
return color.Brightened( 0.7 );
return color;

View File

@ -2,7 +2,7 @@
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2014 CERN
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
@ -45,6 +45,12 @@ class ROUTER;
}
#define PNS_HEAD_TRACE 1
#define PNS_HOVER_ITEM 2
#define PNS_SEMI_SOLID 4
#define PNS_COLLISION 8
class ROUTER_PREVIEW_ITEM : public EDA_ITEM
{
public:
@ -63,7 +69,7 @@ public:
ROUTER_PREVIEW_ITEM( const SHAPE& aShape, KIGFX::VIEW* aView = nullptr);
ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem = nullptr, KIGFX::VIEW* aView = nullptr,
bool aIsHoverItem = false );
int aFlags = 0 );
~ROUTER_PREVIEW_ITEM();
void Update( const PNS::ITEM* aItem );
@ -75,8 +81,6 @@ public:
void SetClearance( int aClearance ) { m_clearance = aClearance; }
void ShowClearance( bool aEnabled ) { m_showClearance = aEnabled; }
void SetIsHeadTrace( bool aIsHead ) { m_isHeadTrace = aIsHead; }
#if defined(DEBUG)
void Show( int aA, std::ostream& aB ) const override {}
#endif
@ -114,8 +118,7 @@ private:
ITEM_TYPE m_type;
bool m_isHeadTrace;
bool m_isHoverItem;
int m_flags;
int m_width;
int m_layer;
int m_originLayer;

View File

@ -288,7 +288,7 @@ public:
void HideItem( PNS::ITEM* aItem ) override {};
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
bool aIsHeadTrace = false ) override {};
int aFlags = 0 ) override {};
PNS::RULE_RESOLVER* GetRuleResolver() override;
private:

View File

@ -278,7 +278,8 @@ void PNS_LOG_PLAYER_KICAD_IFACE::HideItem( PNS::ITEM* aItem )
m_viewTracker->HideItem( aItem );
}
void PNS_LOG_PLAYER_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit, bool aIsHeadTrace )
void PNS_LOG_PLAYER_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit,
int aFlags )
{
//printf("DBG disp %p\n", aItem);
m_viewTracker->DisplayItem( aItem );

View File

@ -69,7 +69,8 @@ public:
~PNS_LOG_PLAYER_KICAD_IFACE();
void HideItem( PNS::ITEM* aItem ) override;
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false, bool aIsHeadTrace = false ) override;
void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
int aFlags = 0 ) override;
int GetNetCode( PNS::NET_HANDLE aNet ) const override;
wxString GetNetName( PNS::NET_HANDLE aNet ) const override;