diff --git a/pcbnew/router/pns_component_dragger.cpp b/pcbnew/router/pns_component_dragger.cpp index c6f50a5c11..968bfe8f35 100644 --- a/pcbnew/router/pns_component_dragger.cpp +++ b/pcbnew/router/pns_component_dragger.cpp @@ -232,7 +232,7 @@ bool COMPONENT_DRAGGER::Drag( const VECTOR2I& aP ) l_new.ClearLinks(); l_new.DragCorner( cn.p_next, cn.origLine.CLine().Find( cn.p_orig ) ); - PNS_DBG( Dbg(), AddLine, l_new.CLine(), BLUE, 100000, "cdrag-new-fanout" ); + PNS_DBG( Dbg(), AddItem, &l_new, BLUE, 0, wxT( "cdrag-new-fanout" ) ); m_draggedItems.Add( l_new ); LINE l_orig( cn.origLine ); diff --git a/pcbnew/router/pns_debug_decorator.h b/pcbnew/router/pns_debug_decorator.h index 871503f9c2..7399de9d9f 100644 --- a/pcbnew/router/pns_debug_decorator.h +++ b/pcbnew/router/pns_debug_decorator.h @@ -26,11 +26,14 @@ #include #include #include +#include #include namespace PNS { +class ITEM; + class DEBUG_DECORATOR { public: @@ -56,27 +59,54 @@ public: void SetDebugEnabled( bool aEnabled ) { m_debugEnabled = aEnabled;} bool IsDebugEnabled() const { return m_debugEnabled; } - virtual void SetIteration( int iter ){}; + 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, + + virtual void NewStage( const wxString& name, int iter, const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){}; - virtual void BeginGroup( const std::string& name, + + virtual void BeginGroup( const wxString& name, int aLevel = 0, const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){}; + virtual void EndGroup( const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){}; + virtual void AddPoint( const VECTOR2I& aP, const KIGFX::COLOR4D& aColor, int aSize, - const std::string& aName, + const wxString& aName = wxT( "" ), 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( const SEG& aS, const KIGFX::COLOR4D& aColor, - const std::string& aName, - const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){}; - virtual void AddBox( const BOX2I& aB, const KIGFX::COLOR4D& aColor, - const std::string& aName, - const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ){}; - virtual void Clear(){}; + + virtual void AddItem( const ITEM* aItem, const KIGFX::COLOR4D& aColor, + int aOverrideWidth = 0, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) {}; + + virtual void AddShape( const SHAPE* aShape, const KIGFX::COLOR4D& aColor, + int aOverrideWidth = 0, + 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() ) + { + SHAPE_RECT r( aBox ); + AddShape( &r, aColor, aOverrideWidth, aName, aSrcLoc ); + } + + void AddShape( const SEG& aSeg, const KIGFX::COLOR4D& aColor, + int aOverrideWidth = 0, + const wxString& aName = wxT( "" ), + const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) + { + SHAPE_LINE_CHAIN lc; + lc.Append( aSeg.A ); + lc.Append( aSeg.B ); + AddShape( &lc, aColor, aOverrideWidth, aName, aSrcLoc ); + } + + virtual void Clear() {}; private: diff --git a/pcbnew/router/pns_dp_meander_placer.cpp b/pcbnew/router/pns_dp_meander_placer.cpp index 130e5b2f20..ac9bdd3ea3 100644 --- a/pcbnew/router/pns_dp_meander_placer.cpp +++ b/pcbnew/router/pns_dp_meander_placer.cpp @@ -205,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( item ) ) - PNS_DBG( Dbg(), AddLine, l->CLine(), YELLOW, 10000, "tuned-path-p" ); + PNS_DBG( Dbg(), AddShape, &l->CLine(), YELLOW, 10000, wxT( "tuned-path-p" ) ); } for( const ITEM* item : m_tunedPathN.CItems() ) { if( const LINE* l = dyn_cast( item ) ) - PNS_DBG( Dbg(), AddLine, l->CLine(), YELLOW, 10000, "tuned-path-n" ); + PNS_DBG( Dbg(), AddShape, &l->CLine(), YELLOW, 10000, wxT( "tuned-path-n" ) ); } int curIndexP = 0, curIndexN = 0; @@ -220,7 +220,7 @@ bool DP_MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem ) { SEG base = baselineSegment( sp ); - PNS_DBG( Dbg(), AddSegment, base, GREEN, "dp-baseline" ); + PNS_DBG( Dbg(), AddShape, base, GREEN, 10000, wxT( "dp-baseline" ) ); while( sp.indexP >= curIndexP && curIndexP != -1 ) { diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 28cf810abe..11d0ee161a 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -474,8 +474,8 @@ 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 - PNS_DBG( Dbg(), AddPoint, anchor, YELLOW, 100000, "drag-anchor" ); - PNS_DBG( Dbg(), AddBox, *affectedArea, RED, "drag-affected-area" ); + PNS_DBG( Dbg(), AddPoint, anchor, YELLOW, 100000, wxT( "drag-anchor" ) ); + PNS_DBG( Dbg(), AddShape, *affectedArea, RED, 0, wxT( "drag-affected-area" ) ); optimizer.SetRestrictArea( *affectedArea ); optimizer.Optimize( &aDragged ); @@ -483,7 +483,7 @@ void DRAGGER::optimizeAndUpdateDraggedLine( LINE& aDragged, const LINE& aOrig, c OPT_BOX2I optArea = aDragged.ChangedArea( &aOrig ); if( optArea ) - PNS_DBG( Dbg(), AddBox, *optArea, BLUE, "drag-opt-area" ); + PNS_DBG( Dbg(), AddShape, *optArea, BLUE, 0, wxT( "drag-opt-area" ) ); m_lastNode->Add( aDragged ); m_draggedItems.Clear(); @@ -578,8 +578,8 @@ bool DRAGGER::dragWalkaround( const VECTOR2I& aP ) if( ok ) { - PNS_DBG( Dbg(), AddLine, origLine.CLine(), BLUE, 50000, "drag-orig-line" ); - PNS_DBG( Dbg(), AddLine, draggedWalk.CLine(), CYAN, 75000, "drag-walk" ); + PNS_DBG( Dbg(), AddShape, &origLine.CLine(), BLUE, 50000, wxT( "drag-orig-line" ) ); + PNS_DBG( Dbg(), AddShape, &draggedWalk.CLine(), CYAN, 75000, wxT( "drag-walk" ) ); m_lastNode->Remove( origLine ); optimizeAndUpdateDraggedLine( draggedWalk, origLine, aP ); } @@ -624,7 +624,7 @@ bool DRAGGER::dragShove( const VECTOR2I& aP ) else dragged.DragCorner( aP, m_draggedSegmentIndex ); - PNS_DBG( Dbg(), AddLine, dragged.CLine(), BLUE, 5000, "drag-shove-line" ); + PNS_DBG( Dbg(), AddShape, &dragged.CLine(), BLUE, 5000, wxT( "drag-shove-line" ) ); SHOVE::SHOVE_STATUS st = m_shove->ShoveLines( dragged ); diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index fab2c3db59..a6681972bb 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -751,10 +751,12 @@ public: m_view->Add( m_items ); } - virtual void AddPoint( const VECTOR2I& aP, const COLOR4D& aColor, int aSize, - const std::string& aName, + 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 + { + #if 0 SHAPE_LINE_CHAIN l; l.Append( aP - VECTOR2I( -aSize, -aSize ) ); @@ -767,52 +769,7 @@ public: l.Append( aP + VECTOR2I( aSize, -aSize ) ); AddLine( l, aColor, 10000, aName ); - } - - virtual void AddBox( const BOX2I& aB, const COLOR4D& aColor, const std::string& aName, - const SRC_LOCATION_INFO& aSrcLoc = SRC_LOCATION_INFO() ) 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, aName, aSrcLoc ); - } - - virtual void AddSegment( const 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, aName, aSrcLoc ); - } - - - 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( nullptr, m_view ); - - pitem->SetColor( aColor ); - pitem->Line( aLine, aWidth ); - - // Should not be needed, as m_items has been passed as a parent group in alloc; - m_items->Add( pitem ); - m_view->Update( m_items ); + #endif } void Clear() override diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index 2515632f55..4e09c12447 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -550,7 +550,7 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead ) do { snprintf( name, sizeof( name ), "walk-round-%d", round ); - PNS_DBG( Dbg(), BeginGroup, name ); + PNS_DBG( Dbg(), BeginGroup, name, 0 ); viaOk = buildInitialLine( walkP, initTrack, round == 0 ); @@ -567,8 +567,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; - PNS_DBG( Dbg(), AddLine, wr.lineCw.CLine(), CYAN, 10000, "wf-result-cw" ); - PNS_DBG( Dbg(), AddLine, wr.lineCcw.CLine(), BLUE, 20000, "wf-result-ccw" ); + PNS_DBG( Dbg(), AddItem, &wr.lineCw, CYAN, 10000, wxT( "wf-result-cw" ) ); + PNS_DBG( Dbg(), AddItem, &wr.lineCcw, BLUE, 20000, wxT( "wf-result-ccw" ) ); int bestLength = len_cw < len_ccw ? len_cw : len_ccw; @@ -596,8 +596,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 ); - PNS_DBG( Dbg(), AddPoint, p_ccw, BLUE, 500000, "hug-target-ccw" ); - PNS_DBG( Dbg(), AddLine, l_ccw, MAGENTA, 200000, "wh-result-ccw" ); + PNS_DBG( Dbg(), AddPoint, p_ccw, BLUE, 500000, wxT( "hug-target-ccw" ) ); + PNS_DBG( Dbg(), AddShape, &l_ccw, MAGENTA, 200000, wxT( "wh-result-ccw" ) ); } } @@ -609,8 +609,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 ); - PNS_DBG( Dbg(), AddPoint, p_cw, YELLOW, 500000, "hug-target-cw" ); - PNS_DBG( Dbg(), AddLine, l_cw, BLUE, 200000, "wh-result-cw" ); + PNS_DBG( Dbg(), AddPoint, p_cw, YELLOW, 500000, wxT( "hug-target-cw" ) ); + PNS_DBG( Dbg(), AddShape, &l_cw, BLUE, 200000, wxT( "wh-result-cw" ) ); } } @@ -641,7 +641,7 @@ bool LINE_PLACER::rhWalkOnly( const VECTOR2I& aP, LINE& aNewHead ) round++; } while( round < 2 && m_placingVia ); - PNS_DBG( Dbg(), AddLine, walkFull.CLine(), GREEN, 200000, "walk-full" ); + PNS_DBG( Dbg(), AddItem, &walkFull, GREEN, 200000, wxT( "walk-full" ) ); switch( Settings().OptimizerEffort() ) { @@ -887,7 +887,7 @@ bool LINE_PLACER::optimizeTailHeadTransition() // the optimized line - PNS_DBG( Dbg(), AddLine, new_head.CLine(), LIGHTCYAN, 10000, "ht-newline" ); + PNS_DBG( Dbg(), AddItem, &new_head, LIGHTCYAN, 10000, wxT( "ht-newline" ) ); if( OPTIMIZER::Optimize( &new_head, OPTIMIZER::MERGE_SEGMENTS, m_currentNode ) ) { @@ -923,41 +923,41 @@ void LINE_PLACER::routeStep( const VECTOR2I& aP ) m_head.ShapeCount(), m_tail.ShapeCount() ); - PNS_DBG( Dbg(), BeginGroup, "route-step" ); + PNS_DBG( Dbg(), BeginGroup, wxT( "route-step" ), 0 ); - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), WHITE, 10000, "tail-init" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), GREEN, 10000, "head-init" ); + PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-init" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-init" ) ); for( i = 0; i < n_iter; i++ ) { if( !go_back && Settings().FollowMouse() ) reduceTail( aP ); - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), WHITE, 10000, "tail-after-reduce" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), GREEN, 10000, "head-after-reduce" ); + PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-after-reduce" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-after-reduce" ) ); go_back = false; if( !routeHead( aP, new_head ) ) + { fail = true; + } - PNS_DBG( Dbg(), AddLine, new_head.CLine(), LIGHTGREEN, 100000, "new_head" ); + PNS_DBG( Dbg(), AddItem, &new_head, LIGHTGREEN, 100000, wxT( "new_head" ) ); if( fail ) break; m_head = new_head; - PNS_DBG( Dbg(), AddLine, m_head.CLine(), LIGHTGREEN, 100000, "head-new" ); - if( handleSelfIntersections() ) { n_iter++; go_back = true; } - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), WHITE, 10000, "tail-after-si" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), GREEN, 10000, "head-after-si" ); + PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-after-si" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-after-si" ) ); if( !go_back && handlePullback() ) { @@ -965,8 +965,8 @@ void LINE_PLACER::routeStep( const VECTOR2I& aP ) go_back = true; } - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), WHITE, 100000, "tail-after-pb" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), GREEN, 100000, "head-after-pb" ); + PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 100000, wxT( "tail-after-pb" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 100000, wxT( "head-after-pb" ) ); } if( fail ) @@ -988,16 +988,16 @@ void LINE_PLACER::routeStep( const VECTOR2I& aP ) if( !fail && Settings().FollowMouse() ) { - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), WHITE, 10000, "tail-pre-merge" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), GREEN, 10000, "head-pre-merge" ); + PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 10000, wxT( "tail-pre-merge" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 10000, wxT( "head-pre-merge" ) ); if( !optimizeTailHeadTransition() ) { mergeHead(); } - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), WHITE, 100000, "tail-post-merge" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), GREEN, 100000, "head-post-merge" ); + PNS_DBG( Dbg(), AddItem, &m_tail, WHITE, 100000, wxT( "tail-post-merge" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, GREEN, 100000, wxT( "head-post-merge" ) ); } PNS_DBGN( Dbg(), EndGroup ); @@ -1022,8 +1022,8 @@ const LINE LINE_PLACER::Trace() const tmp.SetShape( m_tail.CLine() ); tmp.Line().Append( m_head.CLine() ); - PNS_DBG( Dbg(), AddLine, m_tail.CLine(), GREEN, 100000, "tmp-tail" ); - PNS_DBG( Dbg(), AddLine, m_head.CLine(), LIGHTGREEN, 100000, "tmp-head" ); + PNS_DBG( Dbg(), AddItem, &m_tail, GREEN, 100000, wxT( "tmp-tail" ) ); + PNS_DBG( Dbg(), AddItem, &m_head, LIGHTGREEN, 100000, wxT( "tmp-head" ) ); tmp.Line().Simplify(); return tmp; diff --git a/pcbnew/router/pns_meander_placer.cpp b/pcbnew/router/pns_meander_placer.cpp index 95b49dc932..17982952e5 100644 --- a/pcbnew/router/pns_meander_placer.cpp +++ b/pcbnew/router/pns_meander_placer.cpp @@ -160,7 +160,7 @@ bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int a { if( const LINE* l = dyn_cast( item ) ) { - PNS_DBG( Dbg(), AddLine, l->CLine(), BLUE, 30000, "tuned-line" ); + PNS_DBG( Dbg(), AddItem, l, BLUE, 30000, wxT( "tuned-line" ) ); } } diff --git a/pcbnew/router/pns_meander_skew_placer.cpp b/pcbnew/router/pns_meander_skew_placer.cpp index 488ba877b2..0bdfc43ab6 100644 --- a/pcbnew/router/pns_meander_skew_placer.cpp +++ b/pcbnew/router/pns_meander_skew_placer.cpp @@ -142,13 +142,13 @@ bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem ) for( const ITEM* item : m_tunedPathP.CItems() ) { if( const LINE* l = dyn_cast( item ) ) - PNS_DBG( Dbg(), AddLine, l->CLine(), BLUE, 10000, "tuned-path-skew-p" ); + PNS_DBG( Dbg(), AddItem, l, BLUE, 10000, wxT( "tuned-path-skew-p" ) ); } for( const ITEM* item : m_tunedPathN.CItems() ) { if( const LINE* l = dyn_cast( item ) ) - PNS_DBG( Dbg(), AddLine, l->CLine(), YELLOW, 10000, "tuned-path-skew-n" ); + PNS_DBG( Dbg(), AddItem, l, YELLOW, 10000, wxT( "tuned-path-skew-n" ) ); } return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew ); diff --git a/pcbnew/router/pns_mouse_trail_tracer.cpp b/pcbnew/router/pns_mouse_trail_tracer.cpp index 9bfefd30fb..5981d3ab65 100644 --- a/pcbnew/router/pns_mouse_trail_tracer.cpp +++ b/pcbnew/router/pns_mouse_trail_tracer.cpp @@ -76,7 +76,7 @@ void MOUSE_TRAIL_TRACER::AddTrailPoint( const VECTOR2I& aP ) DEBUG_DECORATOR *dbg = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator(); - PNS_DBG( dbg, AddLine, m_trail, CYAN, 50000, "mt-trail" ); + PNS_DBG( dbg, AddShape, &m_trail, CYAN, 50000, wxT( "mt-trail" ) ); } @@ -117,7 +117,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) straight.Append( m_trail.Reverse() ); straight.Simplify(); - PNS_DBG( dbg, AddLine, straight, m_forced ? BLUE : GREEN, 100000, "mt-straight" ); + PNS_DBG( dbg, AddShape, &straight, m_forced ? BLUE : GREEN, 100000, wxT( "mt-straight" ) ); double areaS = straight.Area(); @@ -126,7 +126,7 @@ DIRECTION_45 MOUSE_TRAIL_TRACER::GetPosture( const VECTOR2I& aP ) diag.SetClosed( true ); diag.Simplify(); - PNS_DBG( dbg, AddLine, diag, YELLOW, 100000, "mt-diag" ); + PNS_DBG( dbg, AddShape, &diag, YELLOW, 100000, wxT( "mt-diag" ) ); double areaDiag = diag.Area(); double ratio = areaS / ( areaDiag + 1.0 ); diff --git a/pcbnew/router/pns_optimizer.cpp b/pcbnew/router/pns_optimizer.cpp index 51d06b2c9e..d7693ba90b 100644 --- a/pcbnew/router/pns_optimizer.cpp +++ b/pcbnew/router/pns_optimizer.cpp @@ -603,7 +603,7 @@ bool OPTIMIZER::Optimize( LINE* aLine, LINE* aResult, LINE* aRoot ) if( aRoot ) { - PNS_DBG( dbg, AddLine, aRoot->CLine(), BLUE, 100000, "root-line" ); + PNS_DBG( dbg, AddItem, aRoot, BLUE, 100000, wxT( "root-line" ) ); } diff --git a/pcbnew/router/pns_shove.cpp b/pcbnew/router/pns_shove.cpp index 3219f5fd71..3391a1adec 100644 --- a/pcbnew/router/pns_shove.cpp +++ b/pcbnew/router/pns_shove.cpp @@ -67,10 +67,8 @@ void SHOVE::replaceLine( LINE& aOld, LINE& aNew, bool aIncludeInChangedArea, NOD if( changed_area ) { - if( Dbg() ) - { - Dbg()->AddBox( *changed_area, BLUE, "shove-changed-area" ); - } + SHAPE_RECT r( *changed_area ); + PNS_DBG(Dbg(), AddShape, &r, BLUE, 0, wxT( "shove-changed-area" ) ); m_affectedArea = m_affectedArea ? m_affectedArea->Merge( *changed_area ) : *changed_area; @@ -277,6 +275,8 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE& int attempt; + PNS_DBG( Dbg(), BeginGroup, "shove-details", 1 ); + for( attempt = 0; attempt < 4; attempt++ ) { bool invertTraversal = ( attempt >= 2 ); @@ -290,9 +290,9 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE& { const SHAPE_LINE_CHAIN& hull = aHulls[invertTraversal ? aHulls.size() - 1 - i : i]; - PNS_DBG( Dbg(), AddLine, hull, YELLOW, 10000, "hull" ); - PNS_DBG( Dbg(), AddLine, path, WHITE, l.Width(), "path" ); - PNS_DBG( Dbg(), AddLine, obs, LIGHTGRAY, aObstacleLine.Width(), "obs" ); + PNS_DBG( Dbg(), AddShape, &hull, YELLOW, 10000, wxT( "hull" ) ); + PNS_DBG( Dbg(), AddShape, &path, WHITE, l.Width(), wxT( "path" ) ); + PNS_DBG( Dbg(), AddShape, &obs, LIGHTGRAY, aObstacleLine.Width(), wxT( "obs" ) ); if( !l.Walkaround( hull, path, clockwise ) ) { @@ -300,6 +300,8 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE& hull.Format().c_str(), l.CLine().Format().c_str(), clockwise? 1 : 0) ); + + PNS_DBGN( Dbg(), EndGroup ); return SH_INCOMPLETE; } @@ -358,12 +360,6 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE& bool colliding = l.Collide( &aCurLine, m_currentNode ); -#ifdef DEBUG - char str[128]; - sprintf( str, "att-%d-shoved", attempt ); - Dbg()->AddLine( l.CLine(), BLUE, 20000, str ); -#endif - if(( aCurLine.Marker() & MK_HEAD ) && !colliding ) { JOINT* jtStart = m_currentNode->FindJoint( aCurLine.CPoint( 0 ), &aCurLine ); @@ -384,9 +380,13 @@ SHOVE::SHOVE_STATUS SHOVE::shoveLineToHullSet( const LINE& aCurLine, const LINE& aResultLine.SetShape( l.CLine() ); + PNS_DBGN( Dbg(), EndGroup ); + return SH_OK; } + PNS_DBGN( Dbg(), EndGroup ); + return SH_INCOMPLETE; } @@ -465,12 +465,6 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveObstacleLine( const LINE& aCurLine, const LINE& hulls.push_back( aCurLine.Via().Hull( viaClearance, obstacleLineWidth ) ); } -#ifdef DEBUG - char str[128]; - sprintf( str, "current-cl-%d", clearance ); - Dbg()->AddLine( aCurLine.CLine(), BLUE, 20000, str ); -#endif - rv = shoveLineToHullSet( aCurLine, aObstacleLine, aResultLine, hulls ); } @@ -492,7 +486,10 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacl SEGMENT tmp( *aObstacleSeg ); if( obstacleLine.HasLockedSegments() ) + { + PNS_DBG(Dbg(), Message, "try walk (locked segments)"); return SH_TRY_WALK; + } SHOVE_STATUS rv = ShoveObstacleLine( aCurrent, obstacleLine, shovedLine ); @@ -512,19 +509,10 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSegment( LINE& aCurrent, SEGMENT* aObstacl if( Dbg() ) { - Dbg()->BeginGroup( wxString::Format( wxT( "on-colliding-segment-iter-%d" ), - m_iter ).ToStdString() ); - 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 - Dbg()->Message( "Shove FAIL" ); - - Dbg()->EndGroup(); + PNS_DBG( Dbg(), AddItem, aObstacleSeg, BLUE, 0, wxT( "shove-changed-area" ) ); + PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) ); + PNS_DBG( Dbg(), AddItem, &obstacleLine, GREEN, 10000, wxT( "obstacle-line" ) ); + PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 10000, wxT( "shoved-line" ) ); } if( rv == SH_OK ) @@ -580,16 +568,10 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingArc( LINE& aCurrent, ARC* aObstacleArc ) assert( obstacleLine.LayersOverlap( &shovedLine ) ); - if ( Dbg() ) - { - Dbg()->BeginGroup( wxString::Format( wxT( "on-colliding-arc-iter-%d" ), - m_iter ).ToStdString() ); - 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(); - } + PNS_DBG( Dbg(), AddItem, &tmp, WHITE, 10000, wxT( "obstacle-arc" ) ); + PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) ); + PNS_DBG( Dbg(), AddItem, &obstacleLine, GREEN, 10000, wxT( "obstacle-line" ) ); + PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 10000, wxT( "shoved-line" ) ); if( rv == SH_OK ) { @@ -624,10 +606,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(), RED, 100000, "obstacle-line" ); - Dbg()->AddLine( aCurrent.CLine(), GREEN, 150000, "current-line" ); - Dbg()->AddLine( shovedLine.CLine(), BLUE, 200000, "shoved-line" ); + PNS_DBG( Dbg(), AddItem, &aObstacle, RED, 100000, wxT( "obstacle-line" ) ); + PNS_DBG( Dbg(), AddItem, &aCurrent, GREEN, 150000, wxT( "current-line" ) ); + PNS_DBG( Dbg(), AddItem, &shovedLine, BLUE, 200000, wxT( "shoved-line" ) ); if( rv == SH_OK ) { @@ -766,13 +747,8 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingSolid( LINE& aCurrent, ITEM* aObstacle ) replaceLine( aCurrent, walkaroundLine ); walkaroundLine.SetRank( nextRank ); - if( Dbg() ) - { - Dbg()->BeginGroup( "on-colliding-solid" ); - Dbg()->AddLine( aCurrent.CLine(), RED, 10000, "current-line" ); - Dbg()->AddLine( walkaroundLine.CLine(), BLUE, 10000, "walk-line" ); - Dbg()->EndGroup(); - } + PNS_DBG( Dbg(), AddItem, &aCurrent, RED, 10000, wxT( "current-line" ) ); + PNS_DBG( Dbg(), AddItem, &walkaroundLine, BLUE, 10000, wxT( "walk-line" ) ); popLineStack(); @@ -930,6 +906,7 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in } pushedVia->SetRank( aCurrentRank - 1 ); + PNS_DBG( Dbg(), Message, wxString::Format("PushViaRank %d\n", pushedVia->Rank() ) ); if( aVia->Marker() & MK_HEAD ) // push { @@ -965,6 +942,9 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in replaceLine( lp.first, lp.second ); lp.second.SetRank( aCurrentRank - 1 ); + + PNS_DBG( Dbg(), Message, wxString::Format("PushViaF %p %d\n", &lp.second, lp.second.SegmentCount() ) ); + if( !pushLineStack( lp.second, true ) ) return SH_INCOMPLETE; } @@ -973,8 +953,8 @@ SHOVE::SHOVE_STATUS SHOVE::pushOrShoveVia( VIA* aVia, const VECTOR2I& aForce, in m_currentNode->Remove( lp.first ); } - PNS_DBG( Dbg(), AddLine, lp.first.CLine(), LIGHTGREEN, 10000, "fan-pre" ); - PNS_DBG( Dbg(), AddLine, lp.second.CLine(), LIGHTRED, 10000, "fan-post" ); + PNS_DBG( Dbg(), AddItem, &lp.first, LIGHTGREEN, 10000, wxT( "fan-pre" ) ); + PNS_DBG( Dbg(), AddItem, &lp.second, LIGHTRED, 10000, wxT( "fan-post" ) ); } return SH_OK; @@ -995,16 +975,15 @@ SHOVE::SHOVE_STATUS SHOVE::onCollidingVia( ITEM* aCurrent, VIA* aObstacleVia ) bool viaCollision = false; VECTOR2I mtvLine, mtvVia; - PNS_DBG( Dbg(), BeginGroup, "push-via-by-line" ); + PNS_DBG( Dbg(), BeginGroup, "push-via-by-line", 1 ); if( aCurrent->OfKind( ITEM::LINE_T ) ) { + VIA vtmp ( *aObstacleVia ); LINE* currentLine = (LINE*) aCurrent; -#if 0 - m_logger.NewGroup( "push-via-by-line", m_iter ); - m_logger.Log( currentLine, 4, "current" ); -#endif + PNS_DBG( Dbg(), AddItem, currentLine, LIGHTRED, 10000, wxT( "current-line" ) ); + PNS_DBG( Dbg(), AddItem, &vtmp, LIGHTRED, 100000, wxT( "orig-via" ) ); lineCollision = aObstacleVia->Shape()->Collide( currentLine->Shape(), clearance + currentLine->Width() / 2, @@ -1115,6 +1094,11 @@ SHOVE::SHOVE_STATUS SHOVE::onReverseCollidingVia( LINE& aCurrent, VIA* aObstacle m_logger.Log( &aCurrent, 1, "current-line" ); m_logger.Log( &shoved, 3, "shoved-line" ); #endif + + PNS_DBG( Dbg(), AddItem, aObstacleVia, YELLOW, 0, wxT( "rr-the-via" ) ); + PNS_DBG( Dbg(), AddItem, &aCurrent, BLUE, 0, wxT( "rr-current-line" ) ); + PNS_DBG( Dbg(), AddItem, &shoved, GREEN, 0, wxT( "rr-shoved-line" ) ); + int currentRank = aCurrent.Rank(); replaceLine( aCurrent, shoved ); @@ -1129,12 +1113,19 @@ SHOVE::SHOVE_STATUS SHOVE::onReverseCollidingVia( LINE& aCurrent, VIA* aObstacle void SHOVE::unwindLineStack( LINKED_ITEM* aSeg ) { + int d = 0; + for( std::vector::iterator i = m_lineStack.begin(); i != m_lineStack.end() ; ) { if( i->ContainsLink( aSeg ) ) + { + PNS_DBG(Dbg(), Message, wxString::Format("Unwind lc %d (depth %d/%d)", i->SegmentCount(), d, (int)m_lineStack.size() ) ); i = m_lineStack.erase( i ); + } else i++; + + d++; } for( std::vector::iterator i = m_optimizerQueue.begin(); i != m_optimizerQueue.end() ; ) @@ -1216,9 +1207,12 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) NODE::OPT_OBSTACLE nearest; SHOVE_STATUS st = SH_NULL; -#ifdef DEBUG + if( Dbg() ) + { Dbg()->SetIteration( aIter ); -#endif + } + + PNS_DBG( Dbg(), AddItem, ¤tLine, RED, currentLine.Width(), wxString::Format( "current-coll-chk rank %d", currentLine.Rank() ) ); for( ITEM::PnsKind search_order : { ITEM::SOLID_T, ITEM::VIA_T, ITEM::SEGMENT_T } ) { @@ -1226,8 +1220,8 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) if( nearest ) PNS_DBG( Dbg(), Message, - wxString::Format( wxT( "nearest %p %s" ), nearest->m_item, - nearest->m_item->KindStr() ) ); + wxString::Format( wxT( "nearest %p %s rank %d" ), nearest->m_item, + nearest->m_item->KindStr(), nearest->m_item->Rank() ) ); if( nearest ) break; @@ -1252,7 +1246,7 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) { case ITEM::VIA_T: { - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-via", aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-via", aIter ).ToStdString(), 0 ); if( currentLine.EndsWithVia() ) { @@ -1263,18 +1257,22 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) st = onReverseCollidingVia( currentLine, (VIA*) ni ); } + PNS_DBGN( Dbg(), EndGroup ); + break; } case ITEM::SEGMENT_T: { - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-segment ", - aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-segment ", + aIter ).ToStdString(), 0 ); LINE revLine = assembleLine( static_cast( ni ) ); popLineStack(); st = onCollidingLine( revLine, currentLine ); + PNS_DBGN( Dbg(), EndGroup ); + if( !pushLineStack( revLine ) ) return SH_INCOMPLETE; @@ -1284,12 +1282,14 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) case ITEM::ARC_T: { //TODO(snh): Handle Arc shove separate from track - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: reverse-collide-arc ", aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: reverse-collide-arc ", aIter ).ToStdString(), 0 ); LINE revLine = assembleLine( static_cast( ni ) ); popLineStack(); st = onCollidingLine( revLine, currentLine ); + PNS_DBGN( Dbg(), EndGroup ); + if( !pushLineStack( revLine ) ) return SH_INCOMPLETE; @@ -1307,38 +1307,45 @@ SHOVE::SHOVE_STATUS SHOVE::shoveIteration( int aIter ) switch( ni->Kind() ) { case ITEM::SEGMENT_T: - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: collide-segment ", aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-segment ", aIter ), 0 ); st = onCollidingSegment( currentLine, (SEGMENT*) ni ); if( st == SH_TRY_WALK ) st = onCollidingSolid( currentLine, ni ); + PNS_DBGN( Dbg(), EndGroup ); break; //TODO(snh): Customize Arc collide case ITEM::ARC_T: - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: collide-arc ", aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-arc ", aIter ), 0 ); st = onCollidingArc( currentLine, static_cast( ni ) ); if( st == SH_TRY_WALK ) st = onCollidingSolid( currentLine, ni ); + PNS_DBGN( Dbg(), EndGroup ); + break; case ITEM::VIA_T: - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: shove-via ", aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: collide-via (fixup: %d)", aIter, 0 ), 0 ); st = onCollidingVia( ¤tLine, (VIA*) ni ); if( st == SH_TRY_WALK ) st = onCollidingSolid( currentLine, ni ); + PNS_DBGN( Dbg(), EndGroup ); + break; case ITEM::SOLID_T: - PNS_DBG( Dbg(), Message, wxString::Format( "iter %d: walk-solid ", aIter ) ); + PNS_DBG( Dbg(), BeginGroup, wxString::Format( "iter %d: walk-solid ", aIter ), 0); st = onCollidingSolid( currentLine, (SOLID*) ni ); + PNS_DBGN( Dbg(), EndGroup ); + break; default: @@ -1391,6 +1398,8 @@ SHOVE::SHOVE_STATUS SHOVE::shoveMainLoop() if( st == SH_INCOMPLETE || timeLimit.Expired() || m_iter >= iterLimit ) { + PNS_DBG( Dbg(), Message, wxString::Format( "Fail [time limit expired: %d iter %d iter limit %d", + timeLimit.Expired()?1:0, m_iter, iterLimit ) ); st = SH_INCOMPLETE; break; } @@ -1462,7 +1471,7 @@ SHOVE::SHOVE_STATUS SHOVE::ShoveLines( const LINE& aCurrentHead ) head.Mark( MK_HEAD ); head.SetRank( 100000 ); - PNS_DBG( Dbg(), AddLine, head.CLine(), CYAN, head.Width(), "head, after shove" ); + PNS_DBG( Dbg(), AddItem, &head, CYAN, 0, wxT( "head, after shove" ) ); if( head.EndsWithVia() ) { @@ -1757,10 +1766,9 @@ void SHOVE::runOptimizer( NODE* aNode ) if( area ) { - if( Dbg() ) - { - Dbg()->AddBox( *area, BLUE, "opt-area" ); - } + SHAPE_RECT r( *area ); + + PNS_DBG( Dbg(), AddShape, &r, BLUE, 0, wxT( "opt-area" ) ); optFlags |= OPTIMIZER::RESTRICT_AREA; optimizer.SetRestrictArea( *area, false ); diff --git a/pcbnew/router/pns_walkaround.cpp b/pcbnew/router/pns_walkaround.cpp index df3614a848..88d868551d 100644 --- a/pcbnew/router/pns_walkaround.cpp +++ b/pcbnew/router/pns_walkaround.cpp @@ -67,14 +67,10 @@ WALKAROUND::WALKAROUND_STATUS WALKAROUND::singleStep( LINE& aPath, bool aWinding bool s_cw = aPath.Walkaround( current_obs->m_hull, path_walk, aWindingDirection ); - PNS_DBG( Dbg(), BeginGroup, "hull/walk" ); - char name[128]; - snprintf( name, sizeof( name ), "hull-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration ); - PNS_DBG( Dbg(), AddLine, current_obs->m_hull, RED, 1, name ); - snprintf( name, sizeof( name ), "path-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration ); - PNS_DBG( Dbg(), AddLine, aPath.CLine(), GREEN, 1, name ); - snprintf( name, sizeof( name ), "result-%s-%d", aWindingDirection ? "cw" : "ccw", m_iteration ); - PNS_DBG( Dbg(), AddLine, path_walk, BLUE, 10000, name ); + PNS_DBG( Dbg(), BeginGroup, "hull/walk", 1 ); + PNS_DBG( Dbg(), AddShape, ¤t_obs->m_hull, RED, 0, wxString::Format( "hull-%s-%d", aWindingDirection ? wxT( "cw" ) : wxT( "ccw" ), m_iteration ) ); + PNS_DBG( Dbg(), AddShape, &aPath.CLine(), GREEN, 0, wxString::Format( "path-%s-%d", aWindingDirection ? wxT( "cw" ) : wxT( "ccw" ), m_iteration ) ); + PNS_DBG( Dbg(), AddShape, &path_walk, BLUE, 0, wxString::Format( "result-%s-%d", aWindingDirection ? wxT( "cw" ) : wxT( "ccw" ), m_iteration ) ); PNS_DBG( Dbg(), Message, wxString::Format( wxT( "Stat cw %d" ), !!s_cw ) ); PNS_DBGN( Dbg(), EndGroup );