Show holes in router preview items for vias.

Fixes https://gitlab.com/kicad/code/kicad/issues/9658
This commit is contained in:
Jeff Young 2021-11-19 23:25:25 +00:00
parent a17782d5d2
commit 1f4858c314
4 changed files with 69 additions and 47 deletions

View File

@ -96,6 +96,7 @@ VIA* VIA::Clone() const
v->m_diameter = m_diameter; v->m_diameter = m_diameter;
v->m_drill = m_drill; v->m_drill = m_drill;
v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 ); v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
v->m_hole = SHAPE_CIRCLE( m_pos, m_drill / 2 );
v->m_rank = m_rank; v->m_rank = m_rank;
v->m_marker = m_marker; v->m_marker = m_marker;
v->m_viaType = m_viaType; v->m_viaType = m_viaType;

View File

@ -117,7 +117,12 @@ public:
} }
int Drill() const { return m_drill; } int Drill() const { return m_drill; }
void SetDrill( int aDrill ) { m_drill = aDrill; m_hole.SetRadius( aDrill / 2 ); }
void SetDrill( int aDrill )
{
m_drill = aDrill;
m_hole.SetRadius( m_drill / 2 );
}
bool IsFree() const { return m_isFree; } bool IsFree() const { return m_isFree; }
void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; } void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }

View File

@ -43,6 +43,7 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
m_view = aView; m_view = aView;
m_shape = aItem ? aItem->Shape()->Clone() : nullptr; m_shape = aItem ? aItem->Shape()->Clone() : nullptr;
m_hole = aItem && aItem->Hole() ? aItem->Hole()->Clone() : nullptr;
m_clearance = -1; m_clearance = -1;
m_originLayer = m_layer = LAYER_SELECT_OVERLAY ; m_originLayer = m_layer = LAYER_SELECT_OVERLAY ;
@ -65,6 +66,7 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
ROUTER_PREVIEW_ITEM::~ROUTER_PREVIEW_ITEM() ROUTER_PREVIEW_ITEM::~ROUTER_PREVIEW_ITEM()
{ {
delete m_shape; delete m_shape;
delete m_hole;
} }
@ -72,12 +74,12 @@ void ROUTER_PREVIEW_ITEM::Update( const PNS::ITEM* aItem )
{ {
m_originLayer = aItem->Layers().Start(); m_originLayer = aItem->Layers().Start();
if( const auto l = dyn_cast<const PNS::LINE*>( aItem ) ) if( const PNS::LINE* l = dyn_cast<const PNS::LINE*>( aItem ) )
{ {
if( !l->SegmentCount() ) if( !l->SegmentCount() )
return; return;
} }
else if( const auto v = dyn_cast<const PNS::VIA*>( aItem ) ) else if( const PNS::VIA* v = dyn_cast<const PNS::VIA*>( aItem ) )
{ {
if( v->IsVirtual() ) if( v->IsVirtual() )
return; return;
@ -113,6 +115,19 @@ void ROUTER_PREVIEW_ITEM::Update( const PNS::ITEM* aItem )
m_width = 0; m_width = 0;
m_color = COLOR4D( 0.7, 0.7, 0.7, 0.8 ); m_color = COLOR4D( 0.7, 0.7, 0.7, 0.8 );
m_depth = ViaOverlayDepth; m_depth = ViaOverlayDepth;
delete m_shape;
m_shape = nullptr;
if( aItem->Shape() )
m_shape = aItem->Shape()->Clone();
delete m_hole;
m_hole = nullptr;
if( aItem->Hole() )
m_hole = aItem->Hole()->Clone();
break; break;
case PNS::ITEM::SOLID_T: case PNS::ITEM::SOLID_T:
@ -141,6 +156,10 @@ const BOX2I ROUTER_PREVIEW_ITEM::ViewBBox() const
bbox = m_shape->BBox(); bbox = m_shape->BBox();
bbox.Inflate( m_width / 2 ); bbox.Inflate( m_width / 2 );
} }
if( m_hole )
bbox.Merge( m_hole->BBox() );
return bbox; return bbox;
case PR_POINT: case PR_POINT:
@ -241,7 +260,7 @@ void ROUTER_PREVIEW_ITEM::drawShape( const SHAPE* aShape, KIGFX::GAL* gal ) cons
case SH_CIRCLE: case SH_CIRCLE:
{ {
const SHAPE_CIRCLE* c = (const SHAPE_CIRCLE*) aShape; const SHAPE_CIRCLE* c = static_cast<const SHAPE_CIRCLE*>( aShape );
gal->SetStrokeColor( m_color ); gal->SetStrokeColor( m_color );
if( m_showViaClearance && m_clearance > 0 ) if( m_showViaClearance && m_clearance > 0 )
@ -251,10 +270,24 @@ void ROUTER_PREVIEW_ITEM::drawShape( const SHAPE* aShape, KIGFX::GAL* gal ) cons
} }
gal->SetLayerDepth( m_depth ); gal->SetLayerDepth( m_depth );
gal->SetIsStroke( m_width ? true : false );
gal->SetLineWidth( m_width ); if( m_hole )
gal->SetFillColor( m_color ); {
gal->DrawCircle( c->GetCenter(), c->GetRadius() ); const SHAPE_CIRCLE* h = static_cast<const SHAPE_CIRCLE*>( m_hole );
int halfWidth = m_width / 2;
gal->SetIsStroke( true );
gal->SetIsFill( false );
gal->SetLineWidth( halfWidth + c->GetRadius() - h->GetRadius() );
gal->DrawCircle( c->GetCenter(), ( halfWidth + c->GetRadius() + h->GetRadius() ) / 2 );
}
else
{
gal->SetIsStroke( m_width ? true : false );
gal->SetLineWidth( m_width );
gal->SetFillColor( m_color );
gal->DrawCircle( c->GetCenter(), c->GetRadius() );
}
break; break;
} }
@ -395,9 +428,7 @@ void ROUTER_PREVIEW_ITEM::Line( const SHAPE_LINE_CHAIN& aLine, int aWidth, int a
m_width = aWidth; m_width = aWidth;
if( aStyle >= 0 ) if( aStyle >= 0 )
{
m_color = assignColor( aStyle ); m_color = assignColor( aStyle );
}
m_type = PR_SHAPE; m_type = PR_SHAPE;
m_depth = -1024; // TODO gal->GetMinDepth() m_depth = -1024; // TODO gal->GetMinDepth()
@ -432,32 +463,15 @@ const COLOR4D ROUTER_PREVIEW_ITEM::assignColor( int aStyle ) const
switch( aStyle ) switch( aStyle )
{ {
case 0: case 0: color = COLOR4D( 0, 1, 0, 1 ); break;
color = COLOR4D( 0, 1, 0, 1 ); break; case 1: color = COLOR4D( 1, 0, 0, 1 ); break;
case 2: color = COLOR4D( 1, 1, 0, 1 ); break;
case 1: case 3: color = COLOR4D( 0, 0, 1, 1 ); break;
color = COLOR4D( 1, 0, 0, 1 ); break; case 4: color = COLOR4D( 1, 1, 1, 1 ); break;
case 5: color = COLOR4D( 1, 1, 0, 1 ); break;
case 2: case 6: color = COLOR4D( 0, 1, 1, 1 ); break;
color = COLOR4D( 1, 1, 0, 1 ); break; case 32: color = COLOR4D( 0, 0, 1, 1 ); break;
default: color = COLOR4D( 0.4, 0.4, 0.4, 1 ); break;
case 3:
color = COLOR4D( 0, 0, 1, 1 ); break;
case 4:
color = COLOR4D( 1, 1, 1, 1 ); break;
case 5:
color = COLOR4D( 1, 1, 0, 1 ); break;
case 6:
color = COLOR4D( 0, 1, 1, 1 ); break;
case 32:
color = COLOR4D( 0, 0, 1, 1 ); break;
default:
color = COLOR4D( 0.4, 0.4, 0.4, 1 ); break;
} }
return color; return color;

View File

@ -114,31 +114,33 @@ private:
const KIGFX::COLOR4D assignColor( int aStyle ) const; const KIGFX::COLOR4D assignColor( int aStyle ) const;
const KIGFX::COLOR4D getLayerColor( int aLayer ) const; const KIGFX::COLOR4D getLayerColor( int aLayer ) const;
private:
KIGFX::VIEW* m_view; KIGFX::VIEW* m_view;
PNS::ROUTER* m_router; PNS::ROUTER* m_router;
SHAPE* m_shape; SHAPE* m_shape;
SHAPE* m_hole;
ITEM_TYPE m_type; ITEM_TYPE m_type;
int m_style; int m_style;
int m_width; int m_width;
int m_layer; int m_layer;
int m_originLayer; int m_originLayer;
int m_clearance; int m_clearance;
bool m_showTrackClearance; bool m_showTrackClearance;
bool m_showViaClearance; bool m_showViaClearance;
// fixme: shouldn't this go to VIEW? // fixme: shouldn't this go to VIEW?
static const int ClearanceOverlayDepth; static const int ClearanceOverlayDepth;
static const int BaseOverlayDepth; static const int BaseOverlayDepth;
static const int ViaOverlayDepth; static const int ViaOverlayDepth;
double m_depth; double m_depth;
KIGFX::COLOR4D m_color; KIGFX::COLOR4D m_color;
VECTOR2I m_pos; VECTOR2I m_pos;
}; };
#endif #endif