router: Hotglue the debug graphics back to pcbnew.

This commit is contained in:
Alex 2022-12-30 11:07:44 +05:00
parent cac62aed9e
commit 867a2e833d
3 changed files with 106 additions and 19 deletions

View File

@ -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 );

View File

@ -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;
};

View File

@ -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;