Display clearance for routed tracks (GAL)

This commit is contained in:
Maciej Suminski 2017-01-25 10:33:49 +01:00
parent 487dfeeb01
commit 39317eac83
7 changed files with 79 additions and 28 deletions

View File

@ -68,7 +68,8 @@ public:
PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* aRouter ); PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* aRouter );
virtual ~PNS_PCBNEW_RULE_RESOLVER(); virtual ~PNS_PCBNEW_RULE_RESOLVER();
virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) override; virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const override;
virtual int Clearance( int aNetCode ) const override;
virtual void OverrideClearance( bool aEnable, int aNetA = 0, int aNetB = 0, int aClearance = 0 ) override; virtual void OverrideClearance( bool aEnable, int aNetA = 0, int aNetB = 0, int aClearance = 0 ) override;
virtual void UseDpGap( bool aUseDpGap ) override { m_useDpGap = aUseDpGap; } virtual void UseDpGap( bool aUseDpGap ) override { m_useDpGap = aUseDpGap; }
virtual int DpCoupledNet( int aNet ) override; virtual int DpCoupledNet( int aNet ) override;
@ -107,6 +108,7 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER*
PNS::TOPOLOGY topo( world ); PNS::TOPOLOGY topo( world );
m_netClearanceCache.resize( m_board->GetNetCount() ); m_netClearanceCache.resize( m_board->GetNetCount() );
// Build clearance cache for net classes
for( unsigned int i = 0; i < m_board->GetNetCount(); i++ ) for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
{ {
NETINFO_ITEM* ni = m_board->FindNet( i ); NETINFO_ITEM* ni = m_board->FindNet( i );
@ -127,6 +129,7 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER*
wxLogTrace( "PNS", "Add net %u netclass %s clearance %d", i, netClassName.mb_str(), clearance ); wxLogTrace( "PNS", "Add net %u netclass %s clearance %d", i, netClassName.mb_str(), clearance );
} }
// Build clearance cache for pads
for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() ) for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() )
{ {
auto moduleClearance = mod->GetLocalClearance(); auto moduleClearance = mod->GetLocalClearance();
@ -174,7 +177,7 @@ int PNS_PCBNEW_RULE_RESOLVER::localPadClearance( const PNS::ITEM* aItem ) const
} }
int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const
{ {
int net_a = aA->Net(); int net_a = aA->Net();
int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance ); int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
@ -202,6 +205,15 @@ int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* a
} }
int PNS_PCBNEW_RULE_RESOLVER::Clearance( int aNetCode ) const
{
if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
return m_netClearanceCache[aNetCode].clearance;
return m_defaultClearance;
}
// fixme: ugly hack to make the optimizer respect gap width for currently routed differential pair. // fixme: ugly hack to make the optimizer respect gap width for currently routed differential pair.
void PNS_PCBNEW_RULE_RESOLVER::OverrideClearance( bool aEnable, int aNetA, int aNetB , int aClearance ) void PNS_PCBNEW_RULE_RESOLVER::OverrideClearance( bool aEnable, int aNetA, int aNetB , int aClearance )
{ {
@ -458,7 +470,7 @@ PNS_KICAD_IFACE::~PNS_KICAD_IFACE()
} }
std::unique_ptr< PNS::SOLID > PNS_KICAD_IFACE::syncPad( D_PAD* aPad ) std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
{ {
LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 ); LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
@ -697,7 +709,7 @@ std::unique_ptr< PNS::SOLID > PNS_KICAD_IFACE::syncPad( D_PAD* aPad )
} }
std::unique_ptr< PNS::SEGMENT > PNS_KICAD_IFACE::syncTrack( TRACK* aTrack ) std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE::syncTrack( TRACK* aTrack )
{ {
std::unique_ptr< PNS::SEGMENT > segment( std::unique_ptr< PNS::SEGMENT > segment(
new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() ) new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() )
@ -707,15 +719,14 @@ std::unique_ptr< PNS::SEGMENT > PNS_KICAD_IFACE::syncTrack( TRACK* aTrack )
segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) ); segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
segment->SetParent( aTrack ); segment->SetParent( aTrack );
if( aTrack->IsLocked() ) { if( aTrack->IsLocked() )
segment->Mark( PNS::MK_LOCKED ); segment->Mark( PNS::MK_LOCKED );
}
return segment; return segment;
} }
std::unique_ptr< PNS::VIA > PNS_KICAD_IFACE::syncVia( VIA* aVia ) std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE::syncVia( VIA* aVia )
{ {
LAYER_ID top, bottom; LAYER_ID top, bottom;
aVia->LayerPair( &top, &bottom ); aVia->LayerPair( &top, &bottom );
@ -730,9 +741,8 @@ std::unique_ptr< PNS::VIA > PNS_KICAD_IFACE::syncVia( VIA* aVia )
via->SetParent( aVia ); via->SetParent( aVia );
if( aVia->IsLocked() ) { if( aVia->IsLocked() )
via->Mark( PNS::MK_LOCKED ); via->Mark( PNS::MK_LOCKED );
}
return via; return via;
} }
@ -819,10 +829,20 @@ void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aColor, int aClea
pitem->SetColor( KIGFX::COLOR4D( aColor ) ); pitem->SetColor( KIGFX::COLOR4D( aColor ) );
if( aClearance >= 0 ) if( aClearance >= 0 )
{
pitem->SetClearance( aClearance ); pitem->SetClearance( aClearance );
m_previewItems->Add( pitem ); if( m_dispOptions )
{
auto clearanceDisp = m_dispOptions->m_ShowTrackClearanceMode;
pitem->ShowTrackClearance( clearanceDisp != DO_NOT_SHOW_CLEARANCE );
pitem->ShowViaClearance( clearanceDisp != DO_NOT_SHOW_CLEARANCE
&& clearanceDisp != SHOW_CLEARANCE_NEW_TRACKS );
}
}
m_previewItems->Add( pitem );
m_view->Update( m_previewItems ); m_view->Update( m_previewItems );
} }
@ -954,4 +974,5 @@ void PNS_KICAD_IFACE::SetHostFrame( PCB_EDIT_FRAME* aFrame )
m_frame = aFrame; m_frame = aFrame;
m_commit.reset( new BOARD_COMMIT( m_frame ) ); m_commit.reset( new BOARD_COMMIT( m_frame ) );
m_dispOptions = (DISPLAY_OPTIONS*) m_frame->GetDisplayOptions();
} }

View File

@ -31,6 +31,8 @@ class PNS_PCBNEW_DEBUG_DECORATOR;
class BOARD; class BOARD;
class BOARD_COMMIT; class BOARD_COMMIT;
class DISPLAY_OPTIONS;
namespace KIGFX namespace KIGFX
{ {
class VIEW; class VIEW;
@ -63,9 +65,9 @@ private:
PNS_PCBNEW_RULE_RESOLVER* m_ruleResolver; PNS_PCBNEW_RULE_RESOLVER* m_ruleResolver;
PNS_PCBNEW_DEBUG_DECORATOR* m_debugDecorator; PNS_PCBNEW_DEBUG_DECORATOR* m_debugDecorator;
std::unique_ptr< PNS::SOLID > syncPad( D_PAD* aPad ); std::unique_ptr<PNS::SOLID> syncPad( D_PAD* aPad );
std::unique_ptr< PNS::SEGMENT > syncTrack( TRACK* aTrack ); std::unique_ptr<PNS::SEGMENT> syncTrack( TRACK* aTrack );
std::unique_ptr< PNS::VIA > syncVia( VIA* aVia ); std::unique_ptr<PNS::VIA> syncVia( VIA* aVia );
KIGFX::VIEW* m_view; KIGFX::VIEW* m_view;
KIGFX::VIEW_GROUP* m_previewItems; KIGFX::VIEW_GROUP* m_previewItems;
@ -77,6 +79,7 @@ private:
PICKED_ITEMS_LIST m_undoBuffer; PICKED_ITEMS_LIST m_undoBuffer;
PCB_EDIT_FRAME* m_frame; PCB_EDIT_FRAME* m_frame;
std::unique_ptr<BOARD_COMMIT> m_commit; std::unique_ptr<BOARD_COMMIT> m_commit;
DISPLAY_OPTIONS* m_dispOptions;
}; };
#endif #endif

View File

@ -58,7 +58,8 @@ class RULE_RESOLVER
public: public:
virtual ~RULE_RESOLVER() {} virtual ~RULE_RESOLVER() {}
virtual int Clearance( const ITEM* aA, const ITEM* aB ) = 0; virtual int Clearance( const ITEM* aA, const ITEM* aB ) const = 0;
virtual int Clearance( int aNetCode ) const = 0;
virtual void OverrideClearance( bool aEnable, int aNetA = 0, int aNetB = 0, int aClearance = 0 ) = 0; virtual void OverrideClearance( bool aEnable, int aNetA = 0, int aNetB = 0, int aClearance = 0 ) = 0;
virtual void UseDpGap( bool aUseDpGap ) = 0; virtual void UseDpGap( bool aUseDpGap ) = 0;
virtual int DpCoupledNet( int aNet ) = 0; virtual int DpCoupledNet( int aNet ) = 0;
@ -433,12 +434,10 @@ private:
int aNet ); int aNet );
///> touches a joint and links it to an m_item ///> touches a joint and links it to an m_item
void linkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, void linkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere );
int aNet, ITEM* aWhere );
///> unlinks an item from a joint ///> unlinks an item from a joint
void unlinkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, void unlinkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere );
int aNet, ITEM* aWhere );
///> helpers for adding/removing items ///> helpers for adding/removing items
void addSolid( SOLID* aSeg ); void addSolid( SOLID* aSeg );

View File

@ -26,6 +26,7 @@
#include <view/view_item.h> #include <view/view_item.h>
#include <view/view_group.h> #include <view/view_group.h>
#include <gal/graphics_abstraction_layer.h> #include <gal/graphics_abstraction_layer.h>
#include <gal/color4d.h>
#include <pcb_painter.h> #include <pcb_painter.h>
@ -306,10 +307,12 @@ void ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem )
continue; continue;
const LINE* l = static_cast<const LINE*>( item ); const LINE* l = static_cast<const LINE*>( item );
m_iface->DisplayItem( l ); int clearance = GetRuleResolver()->Clearance( item->Net() );
m_iface->DisplayItem( l, -1, clearance );
if( l->EndsWithVia() ) if( l->EndsWithVia() )
m_iface->DisplayItem( &l->Via() ); m_iface->DisplayItem( &l->Via(), -1, clearance );
} }
//ITEM_SET tmp( &current ); //ITEM_SET tmp( &current );
@ -324,10 +327,10 @@ void ROUTER::CommitRouting( NODE* aNode )
aNode->GetUpdatedItems( removed, added ); aNode->GetUpdatedItems( removed, added );
for ( auto item : removed ) for( auto item : removed )
m_iface->RemoveItem ( item ); m_iface->RemoveItem( item );
for ( auto item : added ) for( auto item : added )
m_iface->AddItem( item ); m_iface->AddItem( item );
m_iface->Commit(); m_iface->Commit();

View File

@ -93,7 +93,7 @@ public:
void SetSuggestFinish( bool aSuggestFinish ) { m_suggestFinish = aSuggestFinish; } void SetSuggestFinish( bool aSuggestFinish ) { m_suggestFinish = aSuggestFinish; }
///> Returns true if Smart Pads (automatic neckdown) is enabled. ///> Returns true if Smart Pads (automatic neckdown) is enabled.
bool SmartPads () const { return m_smartPads; } bool SmartPads() const { return m_smartPads; }
///> Enables/disables Smart Pads (automatic neckdown). ///> Enables/disables Smart Pads (automatic neckdown).
void SetSmartPads( bool aSmartPads ) { m_smartPads = aSmartPads; } void SetSmartPads( bool aSmartPads ) { m_smartPads = aSmartPads; }
@ -134,7 +134,7 @@ public:
TIME_LIMIT WalkaroundTimeLimit() const; TIME_LIMIT WalkaroundTimeLimit() const;
void SetInlineDragEnabled ( bool aEnable ) { m_inlineDragEnabled = aEnable; } void SetInlineDragEnabled ( bool aEnable ) { m_inlineDragEnabled = aEnable; }
bool InlineDragEnabled( ) const { return m_inlineDragEnabled; } bool InlineDragEnabled() const { return m_inlineDragEnabled; }
private: private:
bool m_shoveVias; bool m_shoveVias;

View File

@ -46,6 +46,9 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a
m_clearance = -1; m_clearance = -1;
m_originLayer = m_layer = ITEM_GAL_LAYER( GP_OVERLAY ); m_originLayer = m_layer = ITEM_GAL_LAYER( GP_OVERLAY );
m_showTrackClearance = false;
m_showViaClearance = false;
// initialize variables, overwritten by Update( aItem ), if aItem != NULL // initialize variables, overwritten by Update( aItem ), if aItem != NULL
m_router = NULL; m_router = NULL;
m_type = PR_SHAPE; m_type = PR_SHAPE;
@ -177,6 +180,15 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
{ {
const SHAPE_LINE_CHAIN* l = (const SHAPE_LINE_CHAIN*) m_shape; const SHAPE_LINE_CHAIN* l = (const SHAPE_LINE_CHAIN*) m_shape;
drawLineChain( *l, gal ); drawLineChain( *l, gal );
if( m_showTrackClearance && m_clearance > 0 )
{
gal->SetLayerDepth( ClearanceOverlayDepth );
gal->SetStrokeColor( COLOR4D( DARKDARKGRAY ) );
gal->SetFillColor( COLOR4D( DARKDARKGRAY ) );
gal->SetLineWidth( m_width + 2 * m_clearance );
drawLineChain( *l, gal );
}
break; break;
} }
@ -185,7 +197,7 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) m_shape; const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) m_shape;
gal->DrawSegment( s->GetSeg().A, s->GetSeg().B, s->GetWidth() ); gal->DrawSegment( s->GetSeg().A, s->GetSeg().B, s->GetWidth() );
if( m_clearance > 0 ) if( m_showTrackClearance && m_clearance > 0 )
{ {
gal->SetLayerDepth( ClearanceOverlayDepth ); gal->SetLayerDepth( ClearanceOverlayDepth );
gal->SetStrokeColor( COLOR4D( DARKDARKGRAY ) ); gal->SetStrokeColor( COLOR4D( DARKDARKGRAY ) );
@ -201,7 +213,7 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
const SHAPE_CIRCLE* c = (const SHAPE_CIRCLE*) m_shape; const SHAPE_CIRCLE* c = (const SHAPE_CIRCLE*) m_shape;
gal->DrawCircle( c->GetCenter(), c->GetRadius() ); gal->DrawCircle( c->GetCenter(), c->GetRadius() );
if( m_clearance > 0 ) if( m_showViaClearance && m_clearance > 0 )
{ {
gal->SetLayerDepth( ClearanceOverlayDepth ); gal->SetLayerDepth( ClearanceOverlayDepth );
gal->SetFillColor( COLOR4D( DARKDARKGRAY ) ); gal->SetFillColor( COLOR4D( DARKDARKGRAY ) );

View File

@ -77,6 +77,16 @@ public:
m_clearance = aClearance; m_clearance = aClearance;
} }
void ShowTrackClearance( bool aEnabled )
{
m_showTrackClearance = aEnabled;
}
void ShowViaClearance( bool aEnabled )
{
m_showViaClearance = aEnabled;
}
#if defined(DEBUG) #if defined(DEBUG)
void Show( int aA, std::ostream& aB ) const override {} void Show( int aA, std::ostream& aB ) const override {}
#endif #endif
@ -118,6 +128,9 @@ private:
int m_originLayer; int m_originLayer;
int m_clearance; int m_clearance;
bool m_showTrackClearance;
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;