router: rework router's debugging infrastructure to be more compatibile with the 'qa/pns/pns-log-viewer' tool.

The log viewer tool lets you inspect all the intermediate stages of the routing algorithms. This patch:
- Adds source location tracking of the debug calls (need to use the PNS_DBG macro, sorry)
- Moves some wxLogTrace calls to DEBUG_DECORATOR::Message() so that messages can be displayed alongside the corresponding geometric shapes
This commit is contained in:
Tomasz Wlostowski 2021-05-29 00:09:21 +02:00
parent 1c23b505e0
commit ebd957b08e
16 changed files with 173 additions and 146 deletions

View File

@ -145,7 +145,7 @@ bool COMPONENT_DRAGGER::Drag( const VECTOR2I& aP )
l_new.ClearLinks();
l_new.DragCorner( cn.p_next, cn.origLine.CLine().Find( cn.p_orig ) );
Dbg()->AddLine( l_new.CLine(), 4, 100000 );
PNS_DBG( Dbg(), AddLine, l_new.CLine(), BLUE, 100000, "cdrag-new-fanout" );
m_draggedItems.Add( l_new );
auto l_orig( cn.origLine );

View File

@ -1,7 +1,7 @@
/*
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2016 CERN
* Copyright (C) 2013-2021 CERN
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Christian Gagneraud <chgans@gna.org>
*
@ -27,30 +27,70 @@
#include <geometry/seg.h>
#include <geometry/shape_line_chain.h>
#include <gal/color4d.h>
namespace PNS {
class DEBUG_DECORATOR
{
public:
DEBUG_DECORATOR()
{}
DEBUG_DECORATOR() : m_debugEnabled( false ) {}
virtual ~DEBUG_DECORATOR()
{}
struct SRC_LOCATION_INFO
{
SRC_LOCATION_INFO( std::string aFileName = "", std::string aFuncName = "", int aLine = 0 ) :
fileName( aFileName ), funcName( aFuncName ), line( aLine )
{
}
virtual void SetIteration( int iter ) {};
virtual void Message( const wxString msg ) {};
virtual void NewStage( const std::string& name, int iter ) {};
virtual void BeginGroup( const std::string name ) {};
virtual void EndGroup( ) {};
virtual void AddPoint( VECTOR2I aP, int aColor, int aSize = 100000, const std::string aName = "" ) {};
virtual void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType = 0, int aWidth = 0, const std::string aName = "" ) {};
virtual void AddSegment( SEG aS, int aColor, const std::string aName = "" ) {};
virtual void AddBox( BOX2I aB, int aColor, const std::string aName = "" ) {};
virtual void AddDirections( VECTOR2D aP, int aMask, int aColor, const std::string aName = "" ) {};
virtual void Clear() {};
std::string fileName;
std::string funcName;
int line;
};
virtual ~DEBUG_DECORATOR() {}
void SetDebugEnabled( bool aEnabled ) { m_debugEnabled = aEnabled;}
bool IsDebugEnabled() const { return m_debugEnabled; }
virtual void SetIteration( int iter ){};
virtual void Message( const wxString msg,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void NewStage( const std::string& name, int iter,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void BeginGroup( const std::string name,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void EndGroup( const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void AddPoint( VECTOR2I aP, const KIGFX::COLOR4D& aColor, int aSize,
const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void AddLine( const SHAPE_LINE_CHAIN& aLine, const KIGFX::COLOR4D& aColor,
int aWidth, const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void AddSegment( SEG aS, const KIGFX::COLOR4D& aColor,
const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void AddBox( BOX2I aB, const KIGFX::COLOR4D& aColor,
const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){};
virtual void Clear(){};
private:
bool m_debugEnabled;
};
}
/* WARNING! The marco below is a remarkably ugly hack, intented to log the
call location of the debug calls without having to create the SRC_LOCATION_INFOs every time
DEBUG_DECORATOR::Something() is called.
Also checks if debug is enabled at all prior to calling decorator methods, thus saving some
time wasted otherwise for string formatting and copying the geometry. */
#define PNS_DBG(dbg,method,...) \
if( dbg && dbg->IsDebugEnabled() ) \
dbg->method( __VA_ARGS__, PNS::DEBUG_DECORATOR::SRC_LOCATION_INFO( __FILE__, __FUNCTION__, __LINE__ ) );
} // namespace PNS
#endif

View File

@ -467,8 +467,6 @@ bool DIFF_PAIR_PLACER::FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, IT
{
int netP, netN;
wxLogTrace( "PNS", "world %p", aWorld );
bool result = aWorld->GetRuleResolver()->DpNetPair( aItem, netP, netN );
if( !result )
@ -485,13 +483,9 @@ bool DIFF_PAIR_PLACER::FindDpPrimitivePair( NODE* aWorld, const VECTOR2I& aP, IT
int refNet = aItem->Net();
int coupledNet = ( refNet == netP ) ? netN : netP;
wxLogTrace( "PNS", "result %d", !!result );
OPT_VECTOR2I refAnchor = getDanglingAnchor( aWorld, aItem );
ITEM* primRef = aItem;
wxLogTrace( "PNS", "refAnchor %p", aItem );
if( !refAnchor )
{
if( aErrorMsg )

View File

@ -192,12 +192,6 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
if( coupledSegments.size() == 0 )
return false;
//Router()->DisplayDebugLine( tuned.CP(), 5, 20000 );
//Router()->DisplayDebugLine( tuned.CN(), 4, 20000 );
//Router()->DisplayDebugLine( m_originPair.CP(), 5, 20000 );
//Router()->DisplayDebugLine( m_originPair.CN(), 4, 20000 );
m_result = MEANDERED_LINE( this, true );
m_result.SetWidth( tuned.Width() );
@ -211,13 +205,13 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
for( const ITEM* item : m_tunedPathP.CItems() )
{
if( const LINE* l = dyn_cast<const LINE*>( item ) )
Dbg()->AddLine( l->CLine(), 5, 10000 );
PNS_DBG( Dbg(), AddLine, l->CLine(), YELLOW, 10000, "tuned-path-p" );
}
for( const ITEM* item : m_tunedPathN.CItems() )
{
if( const LINE* l = dyn_cast<const LINE*>( item ) )
Dbg()->AddLine( l->CLine(), 5, 10000 );
PNS_DBG( Dbg(), AddLine, l->CLine(), YELLOW, 10000, "tuned-path-n" );
}
int curIndexP = 0, curIndexN = 0;
@ -226,7 +220,7 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
{
SEG base = baselineSegment( sp );
Dbg()->AddSegment( base, 3 );
PNS_DBG( Dbg(), AddSegment, base, GREEN, "dp-baseline" );
while( sp.indexP >= curIndexP )
{

View File

@ -188,7 +188,7 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
startItem->Unmark( MK_LOCKED );
wxLogTrace( "PNS", "StartDragging: item %p [kind %d]", startItem, (int) startItem->Kind() );
PNS_DBG( Dbg(), Message, wxString::Format( "StartDragging: item %p [kind %d]", startItem, (int) startItem->Kind() ) );
switch( startItem->Kind() )
{
@ -420,15 +420,16 @@ void DRAGGER::optimizeAndUpdateDraggedLine( LINE& aDragged, const LINE& aOrig, c
else if( !affectedArea )
affectedArea = BOX2I( aP ); // No valid area yet? set to minimum to disable optimization
Dbg()->AddPoint( anchor, 3 );
Dbg()->AddBox( *affectedArea, 2 );
PNS_DBG( Dbg(), AddPoint, anchor, YELLOW, 100000, "drag-anchor" );
PNS_DBG( Dbg(), AddBox, *affectedArea, RED, "drag-affected-area" );
optimizer.SetRestrictArea( *affectedArea );
optimizer.Optimize( &aDragged );
OPT_BOX2I optArea = aDragged.ChangedArea( &aOrig );
if( optArea )
Dbg()->AddBox( *optArea, 4 );
PNS_DBG( Dbg(), AddBox, *optArea, BLUE, "drag-opt-area" );
m_lastNode->Add( aDragged );
m_draggedItems.Clear();
@ -511,8 +512,8 @@ bool DRAGGER::dragWalkaround( const VECTOR2I& aP )
if( ok )
{
Dbg()->AddLine( origLine.CLine(), 5, 50000 );
Dbg()->AddLine( draggedWalk.CLine(), 6, 75000 );
PNS_DBG( Dbg(), AddLine, origLine.CLine(), BLUE, 50000, "drag-orig-line" );
PNS_DBG( Dbg(), AddLine, draggedWalk.CLine(), CYAN, 75000, "drag-walk" );
m_lastNode->Remove( origLine );
optimizeAndUpdateDraggedLine( draggedWalk, origLine, aP );
}
@ -556,7 +557,7 @@ bool DRAGGER::dragShove( const VECTOR2I& aP )
else
dragged.DragCorner( aP, m_draggedSegmentIndex );
Dbg()->AddLine( dragged.CLine(), 5, 5000 );
PNS_DBG( Dbg(), AddLine, dragged.CLine(), BLUE, 5000, "drag-shove-line" );
SHOVE::SHOVE_STATUS st = m_shove->ShoveLines( dragged );

View File

@ -725,23 +725,27 @@ public:
m_view->Add( m_items );
}
virtual void AddPoint( VECTOR2I aP, int aColor, int aSize, const std::string aName ) override
{
virtual void AddPoint( VECTOR2I aP, const COLOR4D& aColor, int aSize,
const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
{
SHAPE_LINE_CHAIN l;
l.Append( aP - VECTOR2I( -aSize, -aSize ) );
l.Append( aP + VECTOR2I( -aSize, -aSize ) );
AddLine( l, aColor, 10000 );
AddLine( l, aColor, 10000, aName );
l.Clear();
l.Append( aP - VECTOR2I( aSize, -aSize ) );
l.Append( aP + VECTOR2I( aSize, -aSize ) );
AddLine( l, aColor, 10000 );
AddLine( l, aColor, 10000, aName );
}
void AddBox( BOX2I aB, int aColor, const std::string aName = "" ) override
virtual void AddBox( BOX2I aB, const COLOR4D& aColor,
const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
{
SHAPE_LINE_CHAIN l;
@ -754,44 +758,33 @@ public:
l.Append( o.x, o.y + s.y );
l.Append( o );
AddLine( l, aColor, 10000 );
AddLine( l, aColor, 10000, aName, aSrcLoc );
}
void AddSegment( SEG aS, int aColor, const std::string aName = "" ) override
virtual void AddSegment( SEG aS, const COLOR4D& aColor,
const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
{
SHAPE_LINE_CHAIN l;
l.Append( aS.A );
l.Append( aS.B );
AddLine( l, aColor, 10000 );
AddLine( l, aColor, 10000, aName, aSrcLoc );
}
void AddDirections( VECTOR2D aP, int aMask, int aColor,
const std::string aName = "" ) 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,
const std::string aName = "" ) override
virtual void AddLine( const SHAPE_LINE_CHAIN& aLine, const COLOR4D& aColor,
int aWidth, const std::string aName,
const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) override
{
if( !m_view )
return;
ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( NULL, m_view );
pitem->Line( aLine, aWidth, aType );
pitem->SetColor( aColor );
pitem->Line( aLine, aWidth );
m_items->Add( pitem ); // Should not be needed, as m_items has been passed as a parent group in alloc;
m_view->Update( m_items );
}
@ -1675,8 +1668,8 @@ void PNS_KICAD_IFACE::SetView( KIGFX::VIEW* aView )
auto dec = new PNS_PCBNEW_DEBUG_DECORATOR();
m_debugDecorator = dec;
if( ADVANCED_CFG::GetCfg().m_ShowRouterDebugGraphics )
dec->SetView( m_view );
dec->SetDebugEnabled( ADVANCED_CFG::GetCfg().m_ShowRouterDebugGraphics );
dec->SetView( m_view );
}

View File

@ -552,8 +552,8 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
int len_cw = wr.statusCw == WALKAROUND::DONE ? l_cw.Length() : INT_MAX;
int len_ccw = wr.statusCcw == WALKAROUND::DONE ? l_ccw.Length() : INT_MAX;
Dbg()->AddLine( wr.lineCw.CLine(), 6, 10000, "wf-result-cw" );
Dbg()->AddLine( wr.lineCcw.CLine(), 5, 20000, "wf-result-ccw" );
Dbg()->AddLine( wr.lineCw.CLine(), CYAN, 10000, "wf-result-cw" );
Dbg()->AddLine( wr.lineCcw.CLine(), BLUE, 20000, "wf-result-ccw" );
int bestLength = len_cw < len_ccw ? len_cw : len_ccw;
@ -580,8 +580,8 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
{
int idx_ccw = l_ccw.Split( p_ccw );
l_ccw = l_ccw.Slice( 0, idx_ccw );
Dbg()->AddPoint( p_ccw, 5, 500000, "hug-target-ccw" );
// Dbg()->AddLine( l_ccw, 5, 200000, "wh-result-ccw" );
Dbg()->AddPoint( p_ccw, BLUE, 500000, "hug-target-ccw" );
Dbg()->AddLine( l_ccw, MAGENTA, 200000, "wh-result-ccw" );
}
}
if( wr.statusCw == WALKAROUND::ALMOST_DONE )
@ -591,8 +591,8 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
{
int idx_cw = l_cw.Split( p_cw );
l_cw = l_cw.Slice( 0, idx_cw );
Dbg()->AddPoint( p_cw, 4, 500000, "hug-target-cw" );
// Dbg()->AddLine( l_cw, 6, 200000, "wh-result-cw" );
Dbg()->AddPoint( p_cw, YELLOW, 500000, "hug-target-cw" );
Dbg()->AddLine( l_cw, BLUE, 200000, "wh-result-cw" );
}
}
@ -619,7 +619,7 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
round++;
} while( round < 2 && m_placingVia );
Dbg()->AddLine( walkFull.CLine(), 2, 200000, "walk-full" );
Dbg()->AddLine( walkFull.CLine(), GREEN, 200000, "walk-full" );
switch( Settings().OptimizerEffort() )
{
@ -650,7 +650,6 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead )
}
aNewHead = walkFull;
Dbg()->AddLine( walkFull.CLine(), 2, 200000, "walk-full" );
return true;
}

View File

@ -152,7 +152,7 @@ bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int a
{
if( const LINE* l = dyn_cast<const LINE*>( item ) )
{
Dbg()->AddLine( l->CLine(), 5, 30000 );
PNS_DBG( Dbg(), AddLine, l->CLine(), BLUE, 30000, "tuned-line" );
}
}

View File

@ -140,13 +140,13 @@ bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
for( const ITEM* item : m_tunedPathP.CItems() )
{
if( const LINE* l = dyn_cast<const LINE*>( item ) )
Dbg()->AddLine( l->CLine(), 5, 10000 );
PNS_DBG( Dbg(), AddLine, l->CLine(), BLUE, 10000, "tuned-path-skew-p" );
}
for( const ITEM* item : m_tunedPathN.CItems() )
{
if( const LINE* l = dyn_cast<const LINE*>( item ) )
Dbg()->AddLine( l->CLine(), 4, 10000 );
PNS_DBG( Dbg(), AddLine, l->CLine(), YELLOW, 10000, "tuned-path-skew-n" );
}
return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew );

View File

@ -69,7 +69,9 @@ void MOUSE_TRAIL_TRACER::AddTrailPoint( const VECTOR2I& aP )
m_trail.Simplify();
ROUTER::GetInstance()->GetInterface()->GetDebugDecorator()->AddLine( m_trail, 5, 100000 );
DEBUG_DECORATOR *dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
PNS_DBG( dbg, AddLine, m_trail, CYAN, 100000, "mt-trail" );
}
@ -109,7 +111,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
straight.SetClosed( true );
straight.Append( m_trail.Reverse() );
straight.Simplify();
dbg->AddLine( straight, m_forced ? 3 : 2, 100000 );
PNS_DBG( dbg, AddLine, straight, m_forced ? BLUE : GREEN, 100000, "mt-straight" );
double areaS = std::abs( straight.Area() );
@ -117,7 +120,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
diag.Append( m_trail.Reverse() );
diag.SetClosed( true );
diag.Simplify();
dbg->AddLine( diag, 1, 100000 );
PNS_DBG( dbg, AddLine, diag, YELLOW, 100000, "mt-diag" );
double areaDiag = std::abs( diag.Area() );
double ratio = areaS / ( areaDiag + 1.0 );
@ -126,7 +130,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
// in this case, we cancel any forced posture and restart the trail
if( m_forced && refLength < unlockDistanceFactor * m_tolerance )
{
wxLogTrace( "PNS", "Posture: Unlocked and reset" );
PNS_DBG( dbg, Message, "Posture: Unlocked and reset" );
m_forced = false;
VECTOR2I start = p0;
m_trail.Clear();
@ -163,8 +167,8 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
if( !m_disableMouse && newDirection != m_direction )
{
wxLogTrace( "PNS", "Posture: direction update %s => %s", m_direction.Format(),
newDirection.Format() );
PNS_DBG( dbg, Message, wxString::Format( "Posture: direction update %s => %s", m_direction.Format(),
newDirection.Format() ) );
m_direction = newDirection;
}
@ -172,14 +176,14 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
// to correct to the least obtuse
if( !m_manuallyForced && !m_disableMouse && m_lastSegDirection != DIRECTION_45::UNDEFINED )
{
wxLogTrace( "PNS", "Posture: checking direction %s against last seg %s",
m_direction.Format(), m_lastSegDirection.Format() );
PNS_DBG( dbg, Message, wxString::Format( "Posture: checking direction %s against last seg %s",
m_direction.Format(), m_lastSegDirection.Format() ) );
if( straightDirection == m_lastSegDirection )
{
{
if( m_direction != straightDirection )
{
wxLogTrace( "PNS", "Posture: forcing straight => %s", straightDirection.Format() );
{
PNS_DBG( dbg, Message, wxString::Format( "Posture: forcing straight => %s", straightDirection.Format() ) );
}
m_direction = straightDirection;
@ -188,7 +192,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
{
if( m_direction != straightDirection )
{
wxLogTrace( "PNS", "Posture: forcing diagonal => %s", diagDirection.Format() );
PNS_DBG( dbg, Message, wxString::Format( "Posture: forcing diagonal => %s", diagDirection.Format() ) );
}
m_direction = diagDirection;
@ -200,7 +204,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
case DIRECTION_45::ANG_HALF_FULL:
// Force a better (acute) connection
m_direction = m_direction.IsDiagonal() ? straightDirection : diagDirection;
wxLogTrace( "PNS", "Posture: correcting half full => %s", m_direction.Format() );
PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting half full => %s", m_direction.Format() ) );
break;
case DIRECTION_45::ANG_ACUTE:
@ -211,12 +215,12 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
if( candidate.Angle( m_lastSegDirection ) == DIRECTION_45::ANG_RIGHT )
{
wxLogTrace( "PNS", "Posture: correcting right => %s", candidate.Format() );
PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting right => %s", candidate.Format() ) );
m_direction = candidate;
}
}
break;
}
}
case DIRECTION_45::ANG_RIGHT:
{
@ -226,7 +230,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
if( candidate.Angle( m_lastSegDirection ) == DIRECTION_45::ANG_OBTUSE )
{
wxLogTrace( "PNS", "Posture: correcting obtuse => %s", candidate.Format() );
PNS_DBG( dbg, Message, wxString::Format( "Posture: correcting obtuse => %s", candidate.Format() ) );
m_direction = candidate;
}
@ -242,7 +246,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP )
// If we get far away from the initial point, lock in the current solution to prevent flutter
if( !m_forced && refLength > lockDistanceFactor * m_tolerance )
{
wxLogTrace( "PNS", "Posture: solution locked" );
PNS_DBG( dbg, Message, "Posture: solution locked" );
m_forced = true;
}

View File

@ -408,7 +408,7 @@ NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine, int aKindMask,
if( nearest.m_distFirst == INT_MAX )
nearest.m_item = obstacleList[0].m_item;
debugDecorator->AddLine( nearest.m_hull, 2, 60000, "obstacle-nearest-hull" );
// debugDecorator->AddLine( nearest.m_hull, YELLOW, 60000, "obstacle-nearest-hull" );
return nearest;
}

View File

@ -40,7 +40,6 @@
namespace PNS {
static DEBUG_DECORATOR *g_dbg;
/**
* Cost Estimator Methods
*/
@ -604,11 +603,11 @@ bool OPTIMIZER::mergeColinear( LINE* aLine )
bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult, LINE* aRoot )
{
g_dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
DEBUG_DECORATOR* dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
if( aRoot )
{
g_dbg->AddLine( aRoot->CLine(), 3, 100000 );
PNS_DBG( dbg, AddLine, aRoot->CLine(), BLUE, 100000, "root-line" );
}
@ -1081,8 +1080,6 @@ bool OPTIMIZER::Optimize( LINE* aLine, int aEffortLevel, NODE* aWorld, const VEC
{
OPTIMIZER opt( aWorld );
g_dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
opt.SetEffortLevel( aEffortLevel );
opt.SetCollisionMask( -1 );

View File

@ -66,7 +66,7 @@ void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NOD
{
if( Dbg() )
{
Dbg()->AddBox( *changed_area, 3, "shove-changed-area" );
Dbg()->AddBox( *changed_area, BLUE, "shove-changed-area" );
}
m_affectedArea = m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area;
@ -277,7 +277,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
if( ! l.Walkaround( hull, path, clockwise ) )
{
wxLogTrace("PNS", "Fail-Walk %s %s %d\n", hull.Format().c_str(), l.CLine().Format().c_str(), clockwise? 1:0);
PNS_DBG( Dbg(), Message, wxString::Format( "Fail-Walk %s %s %d\n", hull.Format().c_str(), l.CLine().Format().c_str(), clockwise? 1:0) );
return SH_INCOMPLETE;
}
@ -306,19 +306,19 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
if( ( vFirst < 0 || vLast < 0 ) && !path.CompareGeometry( aObstacleLine.CLine() ) )
{
wxLogTrace( "PNS", "attempt %d fail vfirst-last", attempt );
PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail vfirst-last", attempt ) );
continue;
}
if( path.CPoint( -1 ) != obs.CPoint( -1 ) || path.CPoint( 0 ) != obs.CPoint( 0 ) )
{
wxLogTrace( "PNS", "attempt %d fail vend-start\n", attempt );
PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail vend-start\n", attempt ) );
continue;
}
if( !checkShoveDirection( aCurLine, aObstacleLine, l ) )
{
wxLogTrace( "PNS", "attempt %d fail direction-check", attempt );
PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail direction-check", attempt ) );
aResultLine.SetShape( l.CLine() );
continue;
@ -326,7 +326,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
if( path.SelfIntersecting() )
{
wxLogTrace( "PNS", "attempt %d fail self-intersect", attempt );
PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail self-intersect", attempt ) );
continue;
}
@ -335,7 +335,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
#ifdef DEBUG
char str[128];
sprintf( str, "att-%d-shoved", attempt );
Dbg()->AddLine( l.CLine(), 3, 20000, str );
Dbg()->AddLine( l.CLine(), BLUE, 20000, str );
#endif
if(( aCurLine.Marker() & MK_HEAD ) && !colliding )
@ -351,7 +351,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE&
if( colliding )
{
wxLogTrace( "PNS", "attempt %d fail coll-check", attempt );
PNS_DBG( Dbg(), Message, wxString::Format( "attempt %d fail coll-check", attempt ) );
continue;
}
@ -436,7 +436,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveObstacleLine( const LINE& aCurLine, const LINE&
#ifdef DEBUG
char str[128];
sprintf( str, "current-cl-%d", clearance );
Dbg()->AddLine( aCurLine.CLine(), 5, 20000, str );
Dbg()->AddLine( aCurLine.CLine(), BLUE, 20000, str );
#endif
rv = shoveLineToHullSet( aCurLine, aObstacleLine, aResultLine, hulls );
@ -481,10 +481,10 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacl
if( Dbg() )
{
Dbg()->BeginGroup( wxString::Format( "on-colliding-segment-iter-%d", m_iter ).ToStdString() );
Dbg()->AddSegment( tmp.Seg(), 0, "obstacle-segment" );
Dbg()->AddLine( aCurrent.CLine(), 1, 10000, "current-line" );
Dbg()->AddLine( obstacleLine.CLine(), 2, 10000, "obstacle-line" );
Dbg()->AddLine( shovedLine.CLine(), 3, 10000, "shoved-line" );
Dbg()->AddSegment( tmp.Seg(), WHITE, "obstacle-segment" );
Dbg()->AddLine( aCurrent.CLine(), RED, 10000, "current-line" );
Dbg()->AddLine( obstacleLine.CLine(), GREEN, 10000, "obstacle-line" );
Dbg()->AddLine( shovedLine.CLine(), BLUE, 10000, "shoved-line" );
if( rv == SH_OK )
Dbg()->Message("Shove success");
else
@ -548,10 +548,10 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingArc( LINE& aCurrent, ARC* aObstacleArc )
if ( Dbg() )
{
Dbg()->BeginGroup( wxString::Format( "on-colliding-arc-iter-%d", m_iter ).ToStdString() );
Dbg()->AddLine( tmp.CLine(), 0, 10000, "obstacle-segment" );
Dbg()->AddLine( aCurrent.CLine(), 1, 10000, "current-line" );
Dbg()->AddLine( obstacleLine.CLine(), 2, 10000, "obstacle-line" );
Dbg()->AddLine( shovedLine.CLine(), 3, 10000, "shoved-line" );
Dbg()->AddLine( tmp.CLine(), WHITE, 10000, "obstacle-segment" );
Dbg()->AddLine( aCurrent.CLine(), RED, 10000, "current-line" );
Dbg()->AddLine( obstacleLine.CLine(), GREEN, 10000, "obstacle-line" );
Dbg()->AddLine( shovedLine.CLine(), BLUE, 10000, "shoved-line" );
Dbg()->EndGroup();
}
@ -589,9 +589,9 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingLine( LINE& aCurrent, LINE& aObstacle )
SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, aObstacle, shovedLine );
Dbg()->BeginGroup( "on-colliding-line" );
Dbg()->AddLine( aObstacle.CLine(), 1, 100000, "obstacle-line" );
Dbg()->AddLine( aCurrent.CLine(), 2, 150000, "current-line" );
Dbg()->AddLine( shovedLine.CLine(), 3, 200000, "shoved-line" );
Dbg()->AddLine( aObstacle.CLine(), RED, 100000, "obstacle-line" );
Dbg()->AddLine( aCurrent.CLine(), GREEN, 150000, "current-line" );
Dbg()->AddLine( shovedLine.CLine(), BLUE, 200000, "shoved-line" );
if( rv == SH_OK )
{
@ -731,8 +731,8 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSolid( LINE& aCurrent, ITEM* aObstacle )
if( Dbg() )
{
Dbg()->BeginGroup( "on-colliding-solid" );
Dbg()->AddLine( aCurrent.CLine(), 1, 10000, "current-line" );
Dbg()->AddLine( walkaroundLine.CLine(), 3, 10000, "walk-line" );
Dbg()->AddLine( aCurrent.CLine(), RED, 10000, "current-line" );
Dbg()->AddLine( walkaroundLine.CLine(), BLUE, 10000, "walk-line" );
Dbg()->EndGroup();
}
@ -827,7 +827,7 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in
if( !jt )
{
wxLogTrace( "PNS", "weird, can't find the center-of-via joint\n" );
PNS_DBG( Dbg(), Message, wxString::Format( "weird, can't find the center-of-via joint\n" ) );
return SH_INCOMPLETE;
}
@ -1194,7 +1194,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
{
case ITEM::VIA_T:
{
wxLogTrace( "PNS", "iter %d: reverse-collide-via", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-via", aIter ) );
if( currentLine.EndsWithVia() )
{
@ -1210,7 +1210,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
case ITEM::SEGMENT_T:
{
wxLogTrace( "PNS", "iter %d: reverse-collide-segment ", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-segment ", aIter ) );
LINE revLine = assembleLine( static_cast<SEGMENT*>( ni ) );
popLineStack();
@ -1224,7 +1224,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
case ITEM::ARC_T:
{
//TODO(snh): Handle Arc shove separate from track
wxLogTrace( "PNS", "iter %d: reverse-collide-arc ", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-arc ", aIter ) );
LINE revLine = assembleLine( static_cast<ARC*>( ni ) );
popLineStack();
@ -1246,7 +1246,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
switch( ni->Kind() )
{
case ITEM::SEGMENT_T:
wxLogTrace( "PNS", "iter %d: collide-segment ", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: collide-segment ", aIter ) );
st = onCollidingSegment( currentLine, (SEGMENT*) ni );
@ -1257,7 +1257,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
//TODO(snh): Customize Arc collide
case ITEM::ARC_T:
wxLogTrace( "PNS", "iter %d: collide-arc ", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: collide-arc ", aIter ) );
st = onCollidingArc( currentLine, static_cast<ARC*>( ni ) );
@ -1267,7 +1267,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
break;
case ITEM::VIA_T:
wxLogTrace( "PNS", "iter %d: shove-via ", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: shove-via ", aIter ) );
st = onCollidingVia( &currentLine, (VIA*) ni );
if( st == SH_TRY_WALK )
@ -1276,7 +1276,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter )
break;
case ITEM::SOLID_T:
wxLogTrace( "PNS", "iter %d: walk-solid ", aIter );
PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: walk-solid ", aIter ) );
st = onCollidingSolid( currentLine, (SOLID*) ni );
break;
@ -1301,8 +1301,8 @@ SHOVE::SHOVE_STATUS SHOVE::shoveMainLoop()
m_affectedArea = OPT_BOX2I();
wxLogTrace( "PNS", "ShoveStart [root: %d jts, current: %d jts]", m_root->JointCount(),
m_currentNode->JointCount() );
PNS_DBG( Dbg(), Message, wxString::Format( "ShoveStart [root: %d jts, current: %d jts]", m_root->JointCount(),
m_currentNode->JointCount() ) );
int iterLimit = Settings().ShoveIterationLimit();
TIME_LIMIT timeLimit = Settings().ShoveTimeLimit();
@ -1404,7 +1404,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
{
Dbg()->BeginGroup( "initial" );
Dbg()->AddLine(head.CLine(), 5, head.Width(), "head" );
Dbg()->AddLine(head.CLine(), CYAN, head.Width(), "head" );
Dbg()->EndGroup();
}
@ -1438,8 +1438,8 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead )
m_currentNode->RemoveByMarker( MK_HEAD );
wxLogTrace( "PNS", "Shove status : %s after %d iterations",
( ( st == SH_OK || st == SH_HEAD_MODIFIED ) ? "OK" : "FAILURE"), m_iter );
PNS_DBG( Dbg(), Message, wxString::Format( "Shove status : %s after %d iterations",
( ( st == SH_OK || st == SH_HEAD_MODIFIED ) ? "OK" : "FAILURE"), m_iter ) );
if( st == SH_OK || st == SH_HEAD_MODIFIED )
{
@ -1531,8 +1531,8 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveMultiLines( const ITEM_SET& aHeadSet )
m_currentNode->RemoveByMarker( MK_HEAD );
wxLogTrace( "PNS", "Shove status : %s after %d iterations",
( st == SH_OK ? "OK" : "FAILURE"), m_iter );
PNS_DBG( Dbg(), Message, wxString::Format( "Shove status : %s after %d iterations",
( st == SH_OK ? "OK" : "FAILURE"), m_iter ) );
if( st == SH_OK )
{
@ -1702,7 +1702,7 @@ void SHOVE::runOptimizer( NODE* aNode )
{
if( Dbg() )
{
Dbg()->AddBox( *area, 1, "opt-area" );
Dbg()->AddBox( *area, BLUE, "opt-area" );
}
optFlags |= OPTIMIZER::RESTRICT_AREA;

View File

@ -70,11 +70,11 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::singleStep( LINE& aPath, bool aWinding
Dbg()->BeginGroup("hull/walk");
char name[128];
snprintf(name, sizeof(name), "hull-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
Dbg()->AddLine( current_obs->m_hull, 1, 1, name);
Dbg()->AddLine( current_obs->m_hull, RED, 1, name);
snprintf(name, sizeof(name), "path-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
Dbg()->AddLine( aPath.CLine(), 2, 1, name );
Dbg()->AddLine( aPath.CLine(), GREEN, 1, name );
snprintf(name, sizeof(name), "result-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration );
Dbg()->AddLine( path_walk, 3, 10000, name );
Dbg()->AddLine( path_walk, BLUE, 10000, name );
Dbg()->Message( wxString::Format( "Stat cw %d", !!s_cw ) );
Dbg()->EndGroup();
}

View File

@ -386,7 +386,12 @@ void ROUTER_PREVIEW_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
void ROUTER_PREVIEW_ITEM::Line( const SHAPE_LINE_CHAIN& aLine, int aWidth, int aStyle )
{
m_width = aWidth;
m_color = assignColor( aStyle );
if( aStyle >= 0 )
{
m_color = assignColor( aStyle );
}
m_type = PR_SHAPE;
m_depth = -1024; // TODO gal->GetMinDepth()

View File

@ -60,7 +60,7 @@ public:
void Update( const PNS::ITEM* aItem );
void Line( const SHAPE_LINE_CHAIN& aLine, int aWidth = 0, int aStyle = 0 );
void Line( const SHAPE_LINE_CHAIN& aLine, int aWidth = 0, int aStyle = -1 );
void Box( const BOX2I& aBox, int aStyle = 0 );
void Point ( const VECTOR2I& aPos, int aStyle = 0);