diff --git a/pcbnew/router/pns_algo_base.cpp b/pcbnew/router/pns_algo_base.cpp index b72243b223..c94cac12a6 100644 --- a/pcbnew/router/pns_algo_base.cpp +++ b/pcbnew/router/pns_algo_base.cpp @@ -19,6 +19,7 @@ */ #include "pns_algo_base.h" +#include "pns_debug_decorator.h" #include "pns_router.h" PNS_ROUTING_SETTINGS& PNS_ALGO_BASE::Settings() const diff --git a/pcbnew/router/pns_algo_base.h b/pcbnew/router/pns_algo_base.h index a6429ea602..b618694896 100644 --- a/pcbnew/router/pns_algo_base.h +++ b/pcbnew/router/pns_algo_base.h @@ -21,12 +21,11 @@ #ifndef __PNS_ALGO_BASE_H #define __PNS_ALGO_BASE_H -#include // for wxString - #include "pns_routing_settings.h" class PNS_ROUTER; class PNS_LOGGER; +class PNS_DEBUG_DECORATOR; /** * Class PNS_ALGO_BASE @@ -55,7 +54,23 @@ public: ///> Returns the logger object, allowing to dump geometry to a file. virtual PNS_LOGGER* Logger(); + /** + * Function SetDebugDecorator + * + * Assign a debug decorator allowing this algo to draw extra graphics for visual debugging + */ + void SetDebugDecorator( PNS_DEBUG_DECORATOR *aDecorator ) + { + m_debugDecorator = aDecorator; + } + + PNS_DEBUG_DECORATOR *Dbg() const + { + return m_debugDecorator; + } + private: + PNS_DEBUG_DECORATOR *m_debugDecorator; PNS_ROUTER* m_router; }; diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp index 3293dd4156..1109165cb3 100644 --- a/pcbnew/router/pns_diff_pair_placer.cpp +++ b/pcbnew/router/pns_diff_pair_placer.cpp @@ -35,6 +35,7 @@ #include "pns_diff_pair_placer.h" #include "pns_solid.h" #include "pns_topology.h" +#include "pns_debug_decorator.h" using boost::optional; @@ -826,12 +827,12 @@ void PNS_DIFF_PAIR_PLACER::updateLeadingRatLine() if( topo.LeadingRatLine( &m_currentTrace.PLine(), ratLineP ) ) { - Router()->DisplayDebugLine( ratLineP, 1, 10000 ); + Dbg()->AddLine( ratLineP, 1, 10000 ); } if( topo.LeadingRatLine ( &m_currentTrace.NLine(), ratLineN ) ) { - Router()->DisplayDebugLine( ratLineN, 3, 10000 ); + Dbg()->AddLine( ratLineN, 3, 10000 ); } } diff --git a/pcbnew/router/pns_dp_meander_placer.cpp b/pcbnew/router/pns_dp_meander_placer.cpp index ad9775ac61..493a5ae829 100644 --- a/pcbnew/router/pns_dp_meander_placer.cpp +++ b/pcbnew/router/pns_dp_meander_placer.cpp @@ -207,13 +207,13 @@ bool PNS_DP_MEANDER_PLACER::Move( const VECTOR2I& aP, PNS_ITEM* aEndItem ) for( const PNS_ITEM* item : m_tunedPathP.CItems() ) { if( const PNS_LINE* l = dyn_cast( item ) ) - Router()->DisplayDebugLine( l->CLine(), 5, 10000 ); + Dbg()->AddLine( l->CLine(), 5, 10000 ); } for( const PNS_ITEM* item : m_tunedPathN.CItems() ) { if( const PNS_LINE* l = dyn_cast( item ) ) - Router()->DisplayDebugLine( l->CLine(), 5, 10000 ); + Dbg()->AddLine( l->CLine(), 5, 10000 ); } int curIndexP = 0, curIndexN = 0; @@ -222,7 +222,7 @@ bool PNS_DP_MEANDER_PLACER::Move( const VECTOR2I& aP, PNS_ITEM* aEndItem ) { SEG base = baselineSegment( sp ); - DrawDebugSeg( base, 3 ); + Dbg()->AddSegment( base, 3 ); while( sp.indexP >= curIndexP ) { diff --git a/pcbnew/router/pns_dp_meander_placer.h b/pcbnew/router/pns_dp_meander_placer.h index eb89e106c6..3dd21f3cd0 100644 --- a/pcbnew/router/pns_dp_meander_placer.h +++ b/pcbnew/router/pns_dp_meander_placer.h @@ -33,11 +33,9 @@ #include "pns_meander.h" #include "pns_meander_placer_base.h" #include "pns_diff_pair.h" +#include "pns_debug_decorator.h" class PNS_ROUTER; -class PNS_SHOVE; -class PNS_OPTIMIZER; -class PNS_ROUTER_BASE; /** * Class PNS_DP_MEANDER_PLACER diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 331e27eba5..8e1746bf97 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -1,7 +1,7 @@ /* * KiRouter - a push-and-(sometimes-)shove PCB router * - * Copyright (C) 2013-2014 CERN + * Copyright (C) 2013-2016 CERN * Author: Tomasz Wlostowski * * This program is free software: you can redistribute it and/or modify it @@ -56,6 +56,7 @@ #include "pns_node.h" #include "pns_topology.h" #include "pns_router.h" +#include "pns_debug_decorator.h" #include "router_preview_item.h" class PNS_PCBNEW_RULE_RESOLVER : public PNS_RULE_RESOLVER @@ -248,11 +249,8 @@ bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( PNS_ITEM* aItem, int& aNetP, int& aNet wxString netNameP = aItem->Parent()->GetNet()->GetNetname(); wxString netNameN, netNameCoupled, netNameBase; - bool refIsP = false; int r = matchDpSuffix ( netNameP, netNameCoupled, netNameBase ); - printf("matchDpSuffix %d\n", r); - if( r == 0 ) return false; else if( r == 1 ) @@ -281,22 +279,140 @@ bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( PNS_ITEM* aItem, int& aNetP, int& aNet return true; } +class PNS_PCBNEW_DEBUG_DECORATOR: public PNS_DEBUG_DECORATOR +{ +public: + PNS_PCBNEW_DEBUG_DECORATOR( KIGFX::VIEW *aView = NULL ): PNS_DEBUG_DECORATOR(), + m_view( NULL ), m_items( NULL ) + { + SetView ( aView ); + } + + ~PNS_PCBNEW_DEBUG_DECORATOR() + { + Clear(); + } + + void SetView( KIGFX::VIEW *aView ) + { + Clear(); + delete m_items; + m_items = NULL; + m_view = aView; + if ( m_view == NULL ) + return; + m_items = new KIGFX::VIEW_GROUP( m_view ); + m_items->SetLayer( ITEM_GAL_LAYER( GP_OVERLAY ) ); + m_view->Add( m_items ); + m_items->ViewSetVisible( true ); + } + + void AddPoint( VECTOR2I aP, int aColor ) override + { + SHAPE_LINE_CHAIN l; + + l.Append( aP - VECTOR2I( -50000, -50000 ) ); + l.Append( aP + VECTOR2I( -50000, -50000 ) ); + + AddLine ( l, aColor, 10000 ); + + l.Clear(); + l.Append( aP - VECTOR2I( 50000, -50000 ) ); + l.Append( aP + VECTOR2I( 50000, -50000 ) ); + + AddLine( l, aColor, 10000 ); + } + + void AddBox( BOX2I aB, int aColor ) override + { + SHAPE_LINE_CHAIN l; + + VECTOR2I o = aB.GetOrigin(); + VECTOR2I s = aB.GetSize(); + + l.Append( o ); + l.Append( o.x + s.x, o.y ); + l.Append( o.x + s.x, o.y + s.y ); + l.Append( o.x, o.y + s.y ); + l.Append( o ); + + AddLine( l, aColor, 10000 ); + } + + void AddSegment( SEG aS, int aColor ) override + { + SHAPE_LINE_CHAIN l; + + l.Append( aS.A ); + l.Append( aS.B ); + + AddLine( l, aColor, 10000 ); + } + + void AddDirections( VECTOR2D aP, int aMask, int aColor ) override + { + BOX2I b( aP - VECTOR2I( 10000, 10000 ), VECTOR2I( 20000, 20000 ) ); + + AddBox( b, aColor ); + for( int i = 0; i < 8; i++ ) + { + if( ( 1 << i ) & aMask ) + { + VECTOR2I v = DIRECTION_45( ( DIRECTION_45::Directions ) i ).ToVector() * 100000; + AddSegment( SEG( aP, aP + v ), aColor ); + } + } + } + + void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth ) override + { + ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_items ); + + pitem->Line( aLine, aWidth, aType ); + m_items->Add( pitem ); // Should not be needed, as m_items has been passed as a parent group in alloc; + pitem->ViewSetVisible( true ); + m_items->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY | KIGFX::VIEW_ITEM::APPEARANCE ); + } + + void Clear() override + { + if (m_view && m_items) + { + m_items->FreeItems(); + m_items->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + } + } + +private: + KIGFX::VIEW* m_view; + KIGFX::VIEW_GROUP* m_items; +}; + +PNS_DEBUG_DECORATOR* PNS_KICAD_IFACE::GetDebugDecorator() +{ + return m_debugDecorator; +} + PNS_KICAD_IFACE::PNS_KICAD_IFACE () { m_ruleResolver = nullptr; - m_board = NULL; - m_frame = NULL; - m_view = NULL; + m_board = nullptr; + m_frame = nullptr; + m_view = nullptr; m_previewItems = nullptr; m_world = nullptr; m_router = nullptr; + m_debugDecorator = nullptr; } PNS_KICAD_IFACE::~PNS_KICAD_IFACE () { if( m_ruleResolver ) delete m_ruleResolver; + + if( m_debugDecorator ) + delete m_debugDecorator; } @@ -607,6 +723,9 @@ void PNS_KICAD_IFACE::SyncWorld( PNS_NODE *aWorld ) else if( type == PCB_VIA_T ) item = syncVia( static_cast( t ) ); + if( t->IsLocked() ) + item->Mark ( MK_LOCKED ); + if( item ) aWorld->Add( item ); } @@ -634,10 +753,15 @@ void PNS_KICAD_IFACE::EraseView() m_previewItems->FreeItems(); m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } + + if(m_debugDecorator) + m_debugDecorator->Clear(); } void PNS_KICAD_IFACE::DisplayItem( const PNS_ITEM* aItem, int aColor, int aClearance ) { + printf("DisplayItem %p\n", aItem); + ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_previewItems ); if( aColor >= 0 ) @@ -738,6 +862,7 @@ void PNS_KICAD_IFACE::Commit() void PNS_KICAD_IFACE::SetView ( KIGFX::VIEW *aView ) { + printf("SetView %p\n", aView); if( m_previewItems ) { m_previewItems->FreeItems(); @@ -749,6 +874,12 @@ void PNS_KICAD_IFACE::SetView ( KIGFX::VIEW *aView ) m_previewItems->SetLayer( ITEM_GAL_LAYER( GP_OVERLAY ) ); m_view->Add( m_previewItems ); m_previewItems->ViewSetVisible( true ); + + if( m_debugDecorator ) + delete m_debugDecorator; + + m_debugDecorator = new PNS_PCBNEW_DEBUG_DECORATOR(); + m_debugDecorator->SetView ( m_view ); } void PNS_KICAD_IFACE::UpdateNet ( int aNetCode ) diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index fb7df8d83f..3a60a2caf7 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ - + #ifndef __PNS_KICAD_IFACE_H #define __PNS_KICAD_IFACE_H @@ -26,6 +26,7 @@ #include "pns_router.h" class PNS_PCBNEW_RULE_RESOLVER; +class PNS_PCBNEW_DEBUG_DECORATOR; class BOARD; @@ -55,10 +56,12 @@ public: void UpdateNet ( int aNetCode ); PNS_RULE_RESOLVER* GetRuleResolver(); + PNS_DEBUG_DECORATOR* GetDebugDecorator(); private: PNS_PCBNEW_RULE_RESOLVER* m_ruleResolver; + PNS_PCBNEW_DEBUG_DECORATOR* m_debugDecorator; PNS_ITEM* syncPad( D_PAD* aPad ); PNS_ITEM* syncTrack( TRACK* aTrack ); diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index 210c1ce46c..050123dd12 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -29,6 +29,7 @@ #include "pns_utils.h" #include "pns_router.h" #include "pns_topology.h" +#include "pns_debug_decorator.h" #include @@ -1026,7 +1027,7 @@ void PNS_LINE_PLACER::updateLeadingRatLine() PNS_TOPOLOGY topo( m_lastNode ); if( topo.LeadingRatLine( ¤t, ratLine ) ) - Router()->DisplayDebugLine( ratLine, 5, 10000 ); + Dbg()->AddLine( ratLine, 5, 10000 ); } diff --git a/pcbnew/router/pns_meander_placer.cpp b/pcbnew/router/pns_meander_placer.cpp index 09c0c9398d..f819345fcc 100644 --- a/pcbnew/router/pns_meander_placer.cpp +++ b/pcbnew/router/pns_meander_placer.cpp @@ -27,6 +27,7 @@ #include "pns_topology.h" #include "pns_meander_placer.h" #include "pns_router.h" +#include "pns_debug_decorator.h" PNS_MEANDER_PLACER::PNS_MEANDER_PLACER( PNS_ROUTER* aRouter ) : @@ -149,7 +150,7 @@ bool PNS_MEANDER_PLACER::doMove( const VECTOR2I& aP, PNS_ITEM* aEndItem, int aTa { if( const PNS_LINE* l = dyn_cast( item ) ) { - Router()->DisplayDebugLine( l->CLine(), 5, 30000 ); + Dbg()->AddLine( l->CLine(), 5, 30000 ); } } diff --git a/pcbnew/router/pns_meander_skew_placer.cpp b/pcbnew/router/pns_meander_skew_placer.cpp index 5c29b8d147..2e516d0f4d 100644 --- a/pcbnew/router/pns_meander_skew_placer.cpp +++ b/pcbnew/router/pns_meander_skew_placer.cpp @@ -28,6 +28,7 @@ #include "pns_meander_skew_placer.h" #include "pns_router.h" +#include "pns_debug_decorator.h" PNS_MEANDER_SKEW_PLACER::PNS_MEANDER_SKEW_PLACER ( PNS_ROUTER* aRouter ) : @@ -130,13 +131,13 @@ bool PNS_MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, PNS_ITEM* aEndItem ) for( const PNS_ITEM* item : m_tunedPathP.CItems() ) { if( const PNS_LINE* l = dyn_cast( item ) ) - Router()->DisplayDebugLine( l->CLine(), 5, 10000 ); + Dbg()->AddLine( l->CLine(), 5, 10000 ); } for( const PNS_ITEM* item : m_tunedPathN.CItems() ) { if( const PNS_LINE* l = dyn_cast( item ) ) - Router()->DisplayDebugLine( l->CLine(), 4, 10000 ); + Dbg()->AddLine( l->CLine(), 4, 10000 ); } return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew ); @@ -168,4 +169,3 @@ const wxString PNS_MEANDER_SKEW_PLACER::TuningInfo() const return status; } - diff --git a/pcbnew/router/pns_optimizer.cpp b/pcbnew/router/pns_optimizer.cpp index 061ae76444..ee6c4247cc 100644 --- a/pcbnew/router/pns_optimizer.cpp +++ b/pcbnew/router/pns_optimizer.cpp @@ -298,7 +298,7 @@ int LINE_RESTRICTIONS::allowedAngles( PNS_NODE* aWorld, const PNS_LINE* aLine, c } } - DrawDebugDirs( aP, outputMask, 3 ); + //DrawDebugDirs( aP, outputMask, 3 ); return 0xff; } diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index dc2dda3968..85474b6e85 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -206,6 +206,7 @@ bool PNS_ROUTER::StartDragging( const VECTOR2I& aP, PNS_ITEM* aStartItem ) m_dragger = new PNS_DRAGGER( this ); m_dragger->SetWorld( m_world ); + m_dragger->SetDebugDecorator ( m_iface->GetDebugDecorator () ); if( m_dragger->Start ( aP, aStartItem ) ) m_state = DRAG_SEGMENT; @@ -245,6 +246,7 @@ bool PNS_ROUTER::StartRouting( const VECTOR2I& aP, PNS_ITEM* aStartItem, int aLa m_placer->UpdateSizes ( m_sizes ); m_placer->SetLayer( aLayer ); + m_placer->SetDebugDecorator ( m_iface->GetDebugDecorator () ); bool rv = m_placer->Start( aP, aStartItem ); @@ -263,28 +265,6 @@ void PNS_ROUTER::DisplayItems( const PNS_ITEMSET& aItems ) m_iface->DisplayItem( item ); } -void PNS_ROUTER::DisplayDebugLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth ) -{ -/* ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_previewItems ); - - pitem->Line( aLine, aWidth, aType ); - m_previewItems->Add( pitem ); - pitem->ViewSetVisible( true ); - m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY | KIGFX::VIEW_ITEM::APPEARANCE );*/ -} - - -void PNS_ROUTER::DisplayDebugPoint( const VECTOR2I aPos, int aType ) -{ -/* ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_previewItems ); - - pitem->Point( aPos, aType ); - m_previewItems->Add( pitem ); - pitem->ViewSetVisible( true ); - m_previewItems->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY | KIGFX::VIEW_ITEM::APPEARANCE );*/ -} - - void PNS_ROUTER::Move( const VECTOR2I& aP, PNS_ITEM* endItem ) { m_currentEnd = aP; diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index f9a422e34d..4942ec3f89 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -35,12 +35,8 @@ #include "pns_itemset.h" #include "pns_node.h" -class BOARD; -class BOARD_ITEM; -class D_PAD; -class TRACK; -class VIA; class GRID_HELPER; +class PNS_DEBUG_DECORATOR; class PNS_NODE; class PNS_DIFF_PAIR_PLACER; class PNS_PLACEMENT_ALGO; @@ -95,6 +91,8 @@ enum PNS_ROUTER_MODE { virtual void UpdateNet ( int aNetCode ) = 0; virtual PNS_RULE_RESOLVER* GetRuleResolver() = 0; + virtual PNS_DEBUG_DECORATOR* GetDebugDecorator() = 0; + }; class PNS_ROUTER @@ -140,12 +138,7 @@ public: void DisplayItem( const PNS_ITEM* aItem, int aColor = -1, int aClearance = -1 ); void DisplayItems( const PNS_ITEMSET& aItems ); - - void DisplayDebugLine( const SHAPE_LINE_CHAIN& aLine, int aType = 0, int aWidth = 0 ); - void DisplayDebugPoint( const VECTOR2I aPos, int aType = 0 ); - void DisplayDebugBox( const BOX2I& aBox, int aType = 0, int aWidth = 0 ); void DeleteTraces( PNS_ITEM *aStartItem, bool aWholeTrack ); - void SwitchLayer( int layer ); void ToggleViaPlacement(); @@ -278,7 +271,6 @@ private: VECTOR2I m_currentEnd; RouterState m_state; - //BOARD* m_board; PNS_NODE* m_world; PNS_NODE* m_lastNode; PNS_PLACEMENT_ALGO * m_placer; diff --git a/pcbnew/router/pns_utils.cpp b/pcbnew/router/pns_utils.cpp index f7871bea27..0cb28a1c57 100644 --- a/pcbnew/router/pns_utils.cpp +++ b/pcbnew/router/pns_utils.cpp @@ -163,7 +163,7 @@ SHAPE_RECT ApproximateSegmentAsRect( const SHAPE_SEGMENT& aSeg ) std::abs( p1.x - p0.x ), std::abs( p1.y - p0.y ) ); } - +#if 0 void DrawDebugPoint( VECTOR2I aP, int aColor ) { SHAPE_LINE_CHAIN l; @@ -223,7 +223,7 @@ void DrawDebugDirs( VECTOR2D aP, int aMask, int aColor ) } } } - +#endif OPT_BOX2I ChangedArea( const PNS_ITEM* aItemA, const PNS_ITEM* aItemB ) { diff --git a/pcbnew/router/pns_utils.h b/pcbnew/router/pns_utils.h index bc300a9332..709ec53a41 100644 --- a/pcbnew/router/pns_utils.h +++ b/pcbnew/router/pns_utils.h @@ -52,11 +52,13 @@ const SHAPE_LINE_CHAIN ConvexHull( const SHAPE_CONVEX& convex, int aClearance ); SHAPE_RECT ApproximateSegmentAsRect( const SHAPE_SEGMENT& aSeg ); +#if 0 + void DrawDebugPoint( VECTOR2I aP, int aColor ); void DrawDebugBox( BOX2I aB, int aColor ); void DrawDebugSeg( SEG aS, int aColor ); void DrawDebugDirs( VECTOR2D aP, int aMask, int aColor ); - +#endif OPT_BOX2I ChangedArea( const PNS_ITEM* aItemA, const PNS_ITEM* aItemB ); #endif // __PNS_UTILS_H