From efeae50fbab1f7481eb633dfac7db78ceb936e39 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Fri, 25 Oct 2024 00:28:10 +0200 Subject: [PATCH] router: migrate drag/place algos to use new WALKAROUND class --- pcbnew/router/pns_diff_pair_placer.cpp | 11 +++--- pcbnew/router/pns_dragger.cpp | 32 ++++------------- pcbnew/router/pns_line_placer.cpp | 49 ++++++++++++++------------ 3 files changed, 40 insertions(+), 52 deletions(-) diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp index 1dbdb5a3b8..e015f68e14 100644 --- a/pcbnew/router/pns_diff_pair_placer.cpp +++ b/pcbnew/router/pns_diff_pair_placer.cpp @@ -188,7 +188,7 @@ bool DIFF_PAIR_PLACER::attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent, DIFF_PAIR& bool aPFirst, bool aWindCw, bool aSolidsOnly ) { WALKAROUND walkaround( aNode, Router() ); - WALKAROUND::WALKAROUND_STATUS wf1; + WALKAROUND::STATUS wf1; walkaround.SetSolidsOnly( aSolidsOnly ); walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() ); @@ -222,10 +222,11 @@ bool DIFF_PAIR_PLACER::attemptWalk( NODE* aNode, DIFF_PAIR* aCurrent, DIFF_PAIR& continue; } - wf1 = walkaround.Route( preWalk, postWalk, false ); + // fioxme + //wf1 = walkaround.Route( preWalk, postWalk, false ); - if( wf1 != WALKAROUND::DONE ) - return false; + //if( wf1 != WALKAROUND::DONE ) + // return false; LINE postShove( preShove ); @@ -356,7 +357,7 @@ bool DIFF_PAIR_PLACER::rhShoveOnly( const VECTOR2I& aP ) head.Add( &pLine ); head.Add( &nLine ); - SHOVE::SHOVE_STATUS status = m_shove->ShoveMultiLines( head ); // fixme + SHOVE::SHOVE_STATUS status = SHOVE::SH_INCOMPLETE; //->ShoveMultiLines( head ); m_currentNode = m_shove->CurrentNode(); diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 22f05241b0..76e540d8b5 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -515,43 +515,26 @@ void DRAGGER::optimizeAndUpdateDraggedLine( LINE& aDragged, const LINE& aOrig, c bool DRAGGER::tryWalkaround( NODE* aNode, LINE& aOrig, LINE& aWalk ) { - WALKAROUND walkaround( aNode, Router() ); + WALKAROUND walkaround( aNode, Router() ); bool ok = false; walkaround.SetSolidsOnly( false ); walkaround.SetDebugDecorator( Dbg() ); walkaround.SetLogger( Logger() ); walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() ); + walkaround.SetLengthLimit( true, 30.0 ); + walkaround.SetAllowedPolicies( { WALKAROUND::WP_SHORTEST } ); aWalk = aOrig; WALKAROUND::RESULT wr = walkaround.Route( aWalk ); - if( wr.statusCcw == WALKAROUND::DONE && wr.statusCw == WALKAROUND::DONE ) + if( wr.status[ WALKAROUND::WP_SHORTEST ] == WALKAROUND::ST_DONE ) { - if( wr.lineCw.CLine().PointCount() > 1 - && wr.lineCw.CLine().Length() < wr.lineCcw.CLine().Length() ) - { - aWalk = wr.lineCw; - ok = true; - } - else if( wr.lineCcw.CLine().PointCount() > 1 ) - { - aWalk = wr.lineCcw; - ok = true; - } - } - else if( wr.statusCw == WALKAROUND::DONE && wr.lineCw.CLine().PointCount() > 1 ) - { - aWalk = wr.lineCw; - ok = true; - } - else if( wr.statusCcw == WALKAROUND::DONE && wr.lineCcw.CLine().PointCount() > 1 ) - { - aWalk = wr.lineCcw; - ok = true; + aWalk = wr.lines[ WALKAROUND::WP_SHORTEST ]; + return true; } - return ok; + return false; } @@ -621,7 +604,6 @@ bool DRAGGER::dragWalkaround( const VECTOR2I& aP ) bool DRAGGER::dragShove( const VECTOR2I& aP ) { - bool ok = false; if( m_lastNode ) { diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index c25db89a82..e2bbf772f0 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -563,6 +563,7 @@ bool LINE_PLACER::rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisio walkaround.SetLogger( Logger() ); walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() ); walkaround.SetItemMask( aCollisionMask ); + walkaround.SetAllowedPolicies( { WALKAROUND::WP_CCW, WALKAROUND::WP_CW } ); int round = 0; @@ -597,46 +598,49 @@ bool LINE_PLACER::rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisio optimizer.SetEffortLevel( OPTIMIZER::MERGE_SEGMENTS ); optimizer.SetCollisionMask( aCollisionMask ); - int len_cw = wr.statusCw != WALKAROUND::STUCK ? wr.lineCw.CLine().Length() + using WALKAROUND::WP_CW; + using WALKAROUND::WP_CCW; + + int len_cw = wr.status[WP_CW] != WALKAROUND::ST_STUCK ? wr.lines[WP_CW].CLine().Length() : std::numeric_limits::max(); - int len_ccw = wr.statusCcw != WALKAROUND::STUCK ? wr.lineCcw.CLine().Length() + int len_ccw = wr.status[WP_CCW] != WALKAROUND::ST_STUCK ? wr.lines[WP_CCW].CLine().Length() : std::numeric_limits::max(); - if( wr.statusCw == WALKAROUND::DONE ) + if( wr.status[ WP_CW ] == WALKAROUND::ST_DONE ) { - PNS_DBG( Dbg(), AddItem, &wr.lineCw, BLUE, 20000, wxT( "wf-result-cw-preopt" ) ); + PNS_DBG( Dbg(), AddItem, &wr.lines[WP_CW], BLUE, 20000, wxT( "wf-result-cw-preopt" ) ); LINE tmpHead, tmpTail; - if( splitHeadTail( wr.lineCw, m_tail, tmpHead, tmpTail ) ) + if( splitHeadTail( wr.lines[WP_CW], m_tail, tmpHead, tmpTail ) ) { optimizer.Optimize( &tmpHead ); - wr.lineCw.SetShape( tmpTail.CLine () ); - wr.lineCw.Line().Append( tmpHead.CLine( ) ); + wr.lines[WP_CW].SetShape( tmpTail.CLine () ); + wr.lines[WP_CW].Line().Append( tmpHead.CLine( ) ); } - PNS_DBG( Dbg(), AddItem, &wr.lineCw, RED, 20000, wxT( "wf-result-cw-postopt" ) ); - len_cw = wr.lineCw.CLine().Length(); - bestLine = wr.lineCw; + PNS_DBG( Dbg(), AddItem, &wr.lines[WP_CW], RED, 20000, wxT( "wf-result-cw-postopt" ) ); + len_cw = wr.lines[WP_CW].CLine().Length(); + bestLine = wr.lines[WP_CW]; } - if( wr.statusCcw == WALKAROUND::DONE ) + if( wr.status[WP_CCW] == WALKAROUND::ST_DONE ) { - PNS_DBG( Dbg(), AddItem, &wr.lineCcw, BLUE, 20000, wxT( "wf-result-ccw-preopt" ) ); + PNS_DBG( Dbg(), AddItem, &wr.lines[WP_CCW], BLUE, 20000, wxT( "wf-result-ccw-preopt" ) ); LINE tmpHead, tmpTail; - if( splitHeadTail( wr.lineCw, m_tail, tmpHead, tmpTail ) ) + if( splitHeadTail( wr.lines[WP_CCW], m_tail, tmpHead, tmpTail ) ) { optimizer.Optimize( &tmpHead ); - wr.lineCw.SetShape( tmpTail.CLine () ); - wr.lineCw.Line().Append( tmpHead.CLine( ) ); + wr.lines[WP_CCW].SetShape( tmpTail.CLine () ); + wr.lines[WP_CCW].Line().Append( tmpHead.CLine( ) ); } - PNS_DBG( Dbg(), AddItem, &wr.lineCcw, RED, 20000, wxT( "wf-result-ccw-postopt" ) ); - len_ccw = wr.lineCcw.CLine().Length(); + PNS_DBG( Dbg(), AddItem, &wr.lines[WP_CCW], RED, 20000, wxT( "wf-result-ccw-postopt" ) ); + len_ccw = wr.lines[WP_CCW].CLine().Length(); if( len_ccw < len_cw ) - bestLine = wr.lineCcw; + bestLine = wr.lines[WP_CCW]; } int bestLength = len_cw < len_ccw ? len_cw : len_ccw; @@ -656,9 +660,10 @@ bool LINE_PLACER::rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisio SHAPE_LINE_CHAIN l_cw, l_ccw; - if( wr.statusCw != WALKAROUND::STUCK ) + + if( wr.status[WP_CW] != WALKAROUND::ST_STUCK ) { - validCw = cursorDistMinimum( wr.lineCw.CLine(), aP, hugThresholdLength, l_cw ); + validCw = cursorDistMinimum( wr.lines[WP_CW].CLine(), aP, hugThresholdLength, l_cw ); if( validCw ) distCw = ( aP - l_cw.CPoint( -1 ) ).EuclideanNorm(); @@ -668,9 +673,9 @@ bool LINE_PLACER::rhWalkBase( const VECTOR2I& aP, LINE& aWalkLine, int aCollisio : "colliding" ) ); } - if( wr.statusCcw != WALKAROUND::STUCK ) + if( wr.status[WP_CCW] != WALKAROUND::ST_STUCK ) { - validCcw = cursorDistMinimum( wr.lineCcw.CLine(), aP, hugThresholdLength, l_ccw ); + validCcw = cursorDistMinimum( wr.lines[WP_CCW].CLine(), aP, hugThresholdLength, l_ccw ); if( validCcw ) distCcw = ( aP - l_ccw.CPoint( -1 ) ).EuclideanNorm();