From 39317eac83e68d18268fa49102410a711d25475a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 25 Jan 2017 10:33:49 +0100 Subject: [PATCH] Display clearance for routed tracks (GAL) --- pcbnew/router/pns_kicad_iface.cpp | 41 ++++++++++++++++++++------- pcbnew/router/pns_kicad_iface.h | 9 ++++-- pcbnew/router/pns_node.h | 11 ++++--- pcbnew/router/pns_router.cpp | 13 +++++---- pcbnew/router/pns_routing_settings.h | 4 +-- pcbnew/router/router_preview_item.cpp | 16 +++++++++-- pcbnew/router/router_preview_item.h | 13 +++++++++ 7 files changed, 79 insertions(+), 28 deletions(-) diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index a5d838d987..7ce848b7c6 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -68,7 +68,8 @@ public: PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* aRouter ); 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 UseDpGap( bool aUseDpGap ) override { m_useDpGap = aUseDpGap; } 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 ); m_netClearanceCache.resize( m_board->GetNetCount() ); + // Build clearance cache for net classes for( unsigned int i = 0; i < m_board->GetNetCount(); 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 ); } + // Build clearance cache for pads for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() ) { 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 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. 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_KICAD_IFACE::syncPad( D_PAD* aPad ) { 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_KICAD_IFACE::syncTrack( TRACK* aTrack ) { std::unique_ptr< PNS::SEGMENT > segment( 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->SetParent( aTrack ); - if( aTrack->IsLocked() ) { + if( aTrack->IsLocked() ) segment->Mark( PNS::MK_LOCKED ); - } return segment; } -std::unique_ptr< PNS::VIA > PNS_KICAD_IFACE::syncVia( VIA* aVia ) +std::unique_ptr PNS_KICAD_IFACE::syncVia( VIA* aVia ) { LAYER_ID top, bottom; aVia->LayerPair( &top, &bottom ); @@ -730,9 +741,8 @@ std::unique_ptr< PNS::VIA > PNS_KICAD_IFACE::syncVia( VIA* aVia ) via->SetParent( aVia ); - if( aVia->IsLocked() ) { + if( aVia->IsLocked() ) via->Mark( PNS::MK_LOCKED ); - } return via; } @@ -819,10 +829,20 @@ void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aColor, int aClea pitem->SetColor( KIGFX::COLOR4D( aColor ) ); if( aClearance >= 0 ) + { 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 ); } @@ -954,4 +974,5 @@ void PNS_KICAD_IFACE::SetHostFrame( PCB_EDIT_FRAME* aFrame ) m_frame = aFrame; m_commit.reset( new BOARD_COMMIT( m_frame ) ); + m_dispOptions = (DISPLAY_OPTIONS*) m_frame->GetDisplayOptions(); } diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index 7d5280713c..0d65847776 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -31,6 +31,8 @@ class PNS_PCBNEW_DEBUG_DECORATOR; class BOARD; class BOARD_COMMIT; +class DISPLAY_OPTIONS; + namespace KIGFX { class VIEW; @@ -63,9 +65,9 @@ private: PNS_PCBNEW_RULE_RESOLVER* m_ruleResolver; PNS_PCBNEW_DEBUG_DECORATOR* m_debugDecorator; - std::unique_ptr< PNS::SOLID > syncPad( D_PAD* aPad ); - std::unique_ptr< PNS::SEGMENT > syncTrack( TRACK* aTrack ); - std::unique_ptr< PNS::VIA > syncVia( VIA* aVia ); + std::unique_ptr syncPad( D_PAD* aPad ); + std::unique_ptr syncTrack( TRACK* aTrack ); + std::unique_ptr syncVia( VIA* aVia ); KIGFX::VIEW* m_view; KIGFX::VIEW_GROUP* m_previewItems; @@ -77,6 +79,7 @@ private: PICKED_ITEMS_LIST m_undoBuffer; PCB_EDIT_FRAME* m_frame; std::unique_ptr m_commit; + DISPLAY_OPTIONS* m_dispOptions; }; #endif diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h index e584e0cfbb..993eba3b8b 100644 --- a/pcbnew/router/pns_node.h +++ b/pcbnew/router/pns_node.h @@ -58,7 +58,8 @@ class RULE_RESOLVER public: 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 UseDpGap( bool aUseDpGap ) = 0; virtual int DpCoupledNet( int aNet ) = 0; @@ -433,18 +434,16 @@ private: int aNet ); ///> touches a joint and links it to an m_item - void linkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, - int aNet, ITEM* aWhere ); + void linkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere ); ///> unlinks an item from a joint - void unlinkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, - int aNet, ITEM* aWhere ); + void unlinkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere ); ///> helpers for adding/removing items void addSolid( SOLID* aSeg ); void addSegment( SEGMENT* aSeg ); void addVia( VIA* aVia ); - + void removeLine( LINE& aLine ); void removeSolidIndex( SOLID* aSeg ); void removeSegmentIndex( SEGMENT* aSeg ); diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index 044e70d30a..1dbfc2d785 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -306,10 +307,12 @@ void ROUTER::movePlacing( const VECTOR2I& aP, ITEM* aEndItem ) continue; const LINE* l = static_cast( item ); - m_iface->DisplayItem( l ); + int clearance = GetRuleResolver()->Clearance( item->Net() ); + + m_iface->DisplayItem( l, -1, clearance ); if( l->EndsWithVia() ) - m_iface->DisplayItem( &l->Via() ); + m_iface->DisplayItem( &l->Via(), -1, clearance ); } //ITEM_SET tmp( ¤t ); @@ -324,10 +327,10 @@ void ROUTER::CommitRouting( NODE* aNode ) aNode->GetUpdatedItems( removed, added ); - for ( auto item : removed ) - m_iface->RemoveItem ( item ); + for( auto item : removed ) + m_iface->RemoveItem( item ); - for ( auto item : added ) + for( auto item : added ) m_iface->AddItem( item ); m_iface->Commit(); diff --git a/pcbnew/router/pns_routing_settings.h b/pcbnew/router/pns_routing_settings.h index b386c3baac..1aefa736d9 100644 --- a/pcbnew/router/pns_routing_settings.h +++ b/pcbnew/router/pns_routing_settings.h @@ -93,7 +93,7 @@ public: void SetSuggestFinish( bool aSuggestFinish ) { m_suggestFinish = aSuggestFinish; } ///> 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). void SetSmartPads( bool aSmartPads ) { m_smartPads = aSmartPads; } @@ -134,7 +134,7 @@ public: TIME_LIMIT WalkaroundTimeLimit() const; void SetInlineDragEnabled ( bool aEnable ) { m_inlineDragEnabled = aEnable; } - bool InlineDragEnabled( ) const { return m_inlineDragEnabled; } + bool InlineDragEnabled() const { return m_inlineDragEnabled; } private: bool m_shoveVias; diff --git a/pcbnew/router/router_preview_item.cpp b/pcbnew/router/router_preview_item.cpp index 5b0c27352d..7eaf0bc636 100644 --- a/pcbnew/router/router_preview_item.cpp +++ b/pcbnew/router/router_preview_item.cpp @@ -46,6 +46,9 @@ ROUTER_PREVIEW_ITEM::ROUTER_PREVIEW_ITEM( const PNS::ITEM* aItem, KIGFX::VIEW* a m_clearance = -1; m_originLayer = m_layer = ITEM_GAL_LAYER( GP_OVERLAY ); + m_showTrackClearance = false; + m_showViaClearance = false; + // initialize variables, overwritten by Update( aItem ), if aItem != NULL m_router = NULL; 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; 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; } @@ -185,7 +197,7 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const const SHAPE_SEGMENT* s = (const SHAPE_SEGMENT*) m_shape; gal->DrawSegment( s->GetSeg().A, s->GetSeg().B, s->GetWidth() ); - if( m_clearance > 0 ) + if( m_showTrackClearance && m_clearance > 0 ) { gal->SetLayerDepth( ClearanceOverlayDepth ); 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; gal->DrawCircle( c->GetCenter(), c->GetRadius() ); - if( m_clearance > 0 ) + if( m_showViaClearance && m_clearance > 0 ) { gal->SetLayerDepth( ClearanceOverlayDepth ); gal->SetFillColor( COLOR4D( DARKDARKGRAY ) ); diff --git a/pcbnew/router/router_preview_item.h b/pcbnew/router/router_preview_item.h index 094e7ddcdb..05c3aeb4c3 100644 --- a/pcbnew/router/router_preview_item.h +++ b/pcbnew/router/router_preview_item.h @@ -77,6 +77,16 @@ public: m_clearance = aClearance; } + void ShowTrackClearance( bool aEnabled ) + { + m_showTrackClearance = aEnabled; + } + + void ShowViaClearance( bool aEnabled ) + { + m_showViaClearance = aEnabled; + } + #if defined(DEBUG) void Show( int aA, std::ostream& aB ) const override {} #endif @@ -118,6 +128,9 @@ private: int m_originLayer; int m_clearance; + bool m_showTrackClearance; + bool m_showViaClearance; + // fixme: shouldn't this go to VIEW? static const int ClearanceOverlayDepth; static const int BaseOverlayDepth;