From 867a2e833dfc582ab054e37b2c4fa9a2d34a9f63 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 30 Dec 2022 11:07:44 +0500 Subject: [PATCH] router: Hotglue the debug graphics back to pcbnew. --- pcbnew/router/pns_debug_decorator.h | 7 +- pcbnew/router/pns_kicad_iface.cpp | 108 ++++++++++++++++++++++++---- pcbnew/router/router_preview_item.h | 10 +++ 3 files changed, 106 insertions(+), 19 deletions(-) diff --git a/pcbnew/router/pns_debug_decorator.h b/pcbnew/router/pns_debug_decorator.h index 7399de9d9f..0569712916 100644 --- a/pcbnew/router/pns_debug_decorator.h +++ b/pcbnew/router/pns_debug_decorator.h @@ -86,10 +86,9 @@ public: const wxString& aName = wxT( "" ), const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) {}; - void AddShape( const BOX2I& aBox, const KIGFX::COLOR4D& aColor, - int aOverrideWidth = 0, - const wxString& aName = wxT( "" ), - const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) + virtual void AddShape( const BOX2I& aBox, const KIGFX::COLOR4D& aColor, int aOverrideWidth = 0, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) { SHAPE_RECT r( aBox ); AddShape( &r, aColor, aOverrideWidth, aName, aSrcLoc ); diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 521c481645..a4ef722b2f 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -871,17 +871,20 @@ public: PNS_PCBNEW_DEBUG_DECORATOR( KIGFX::VIEW* aView = nullptr ) : PNS::DEBUG_DECORATOR(), m_view( nullptr ), - m_items( nullptr ) + m_items( nullptr ), + m_depth( 0 ) { SetView( aView ); } + ~PNS_PCBNEW_DEBUG_DECORATOR() { PNS_PCBNEW_DEBUG_DECORATOR::Clear(); delete m_items; } + void SetView( KIGFX::VIEW* aView ) { Clear(); @@ -892,44 +895,119 @@ public: if( m_view == nullptr ) return; + if( m_view->GetGAL() ) + m_depth = m_view->GetGAL()->GetMinDepth(); + m_items = new KIGFX::VIEW_GROUP( m_view ); m_items->SetLayer( LAYER_SELECT_OVERLAY ) ; m_view->Add( m_items ); } - virtual void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize, - const wxString& aName = wxT( "" ), - const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override + + void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override { - #if 0 - SHAPE_LINE_CHAIN l; + SHAPE_LINE_CHAIN sh; - l.Append( aP - VECTOR2I( -aSize, -aSize ) ); - l.Append( aP + VECTOR2I( -aSize, -aSize ) ); + sh.SetWidth( 10000 ); - AddLine( l, aColor, 10000, aName ); + sh.Append( aP.x - aSize, aP.y - aSize ); + sh.Append( aP.x + aSize, aP.y + aSize ); + sh.Append( aP.x, aP.y ); + sh.Append( aP.x - aSize, aP.y + aSize ); + sh.Append( aP.x + aSize, aP.y - aSize ); - l.Clear(); - l.Append( aP - VECTOR2I( aSize, -aSize ) ); - l.Append( aP + VECTOR2I( aSize, -aSize ) ); - - AddLine( l, aColor, 10000, aName ); - #endif + AddShape( &sh, aColor, sh.Width(), aName, aSrcLoc ); } + + void AddItem( const PNS::ITEM* aItem, const KIGFX::COLOR4D& aColor, int aOverrideWidth = 0, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) + { + if( !m_view || !aItem ) + return; + + ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view ); + + pitem->SetColor( aColor.WithAlpha( 0.5 ) ); + pitem->SetWidth( aOverrideWidth ); + pitem->SetDepth( nextDepth() ); + + m_items->Add( pitem ); + m_view->Update( m_items ); + } + + + void AddShape( const BOX2I& aBox, const KIGFX::COLOR4D& aColor, int aOverrideWidth = 0, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override + { + SHAPE_LINE_CHAIN l; + l.SetWidth( aOverrideWidth ); + + VECTOR2I o = aBox.GetOrigin(); + VECTOR2I s = aBox.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 ); + + AddShape( &l, aColor, aOverrideWidth, aName, aSrcLoc ); + } + + + void AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor, int aOverrideWidth = 0, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) + { + if( !m_view || !aShape ) + return; + + ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( *aShape, m_view ); + + pitem->SetColor( aColor.WithAlpha( 0.5 ) ); + pitem->SetWidth( aOverrideWidth ); + pitem->SetDepth( nextDepth() ); + + m_items->Add( pitem ); + m_view->Update( m_items ); + } + + void Clear() override { if( m_view && m_items ) { m_items->FreeItems(); m_view->Update( m_items ); + + if( m_view->GetGAL() ) + m_depth = m_view->GetGAL()->GetMinDepth(); } } private: + double nextDepth() + { + // Use different depths so that the transculent shapes won't overwrite each other. + + m_depth++; + + if( m_depth >= 0 && m_view->GetGAL() ) + m_depth = m_view->GetGAL()->GetMinDepth(); + + return m_depth; + } + KIGFX::VIEW* m_view; KIGFX::VIEW_GROUP* m_items; + + double m_depth; }; diff --git a/pcbnew/router/router_preview_item.h b/pcbnew/router/router_preview_item.h index 637dd8cb28..966328a5ae 100644 --- a/pcbnew/router/router_preview_item.h +++ b/pcbnew/router/router_preview_item.h @@ -66,6 +66,16 @@ public: m_color = aColor; } + void SetDepth( double aDepth ) + { + m_depth = aDepth; + } + + void SetWidth( double aWidth ) + { + m_width = aWidth; + } + void SetClearance( int aClearance ) { m_clearance = aClearance;