From 81d4e06f00689d964c52bfac67bae2ee6c353082 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Tue, 29 Dec 2020 01:06:46 -0500 Subject: [PATCH] PNS: Consider pad orientation when routing PNS: Skip smart pads when posture was manually forced This allows a more-correct pad breakout to be chosen when smart pads is off. --- pcbnew/router/pns_kicad_iface.cpp | 1 + pcbnew/router/pns_line_placer.cpp | 14 +++++++++++--- pcbnew/router/pns_line_placer.h | 2 ++ pcbnew/router/pns_optimizer.cpp | 2 +- pcbnew/router/pns_solid.h | 5 +++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index d00757fda1..7b4378ac78 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -831,6 +831,7 @@ std::unique_ptr PNS_KICAD_IFACE_BASE::syncPad( PAD* aPad ) solid->SetNet( aPad->GetNetCode() ); solid->SetParent( aPad ); solid->SetPadToDie( aPad->GetPadToDieLength() ); + solid->SetOrientation( aPad->GetOrientation() ); wxPoint wx_c = aPad->ShapePos(); wxPoint offset = aPad->GetOffset(); diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index f9662b69fb..99fdb97313 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -28,6 +28,7 @@ #include "pns_node.h" #include "pns_router.h" #include "pns_shove.h" +#include "pns_solid.h" #include "pns_topology.h" #include "pns_walkaround.h" @@ -702,7 +703,7 @@ bool LINE_PLACER::rhShoveOnly( const VECTOR2I& aP, LINE& aNewHead ) int effortLevel = OPTIMIZER::MERGE_OBTUSE; - if( Settings().SmartPads() ) + if( Settings().SmartPads() && !m_postureSolver.IsManuallyForced() ) effortLevel = OPTIMIZER::SMART_PADS; optimizer.SetEffortLevel( effortLevel ); @@ -995,6 +996,13 @@ bool LINE_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem ) seg.B.y = -seg.B.y; lastSegDir = DIRECTION_45( seg ); } + else if( aStartItem && aStartItem->Kind() == ITEM::SOLID_T && + static_cast( aStartItem )->Parent()->Type() == PCB_PAD_T ) + { + double angle = static_cast( aStartItem )->GetOrientation() / 10.0; + angle = ( angle + 22.5 ) / 45.0; + lastSegDir = DIRECTION_45( static_cast( int( angle ) ) ); + } m_postureSolver.Clear(); m_postureSolver.AddTrailPoint( aP ); @@ -1608,9 +1616,9 @@ DIRECTION_45 POSTURE_SOLVER::GetPosture( const VECTOR2I& aP ) // Adjusts how close to p0 we unlock the posture again if one was locked already const int unlockDistanceFactor = 4; - if( m_disabled || m_trail.PointCount() < 2 ) + if( m_disabled || m_trail.PointCount() < 2 || m_manuallyForced ) { - if( m_lastSegDirection != DIRECTION_45::UNDEFINED ) + if( !m_manuallyForced && m_lastSegDirection != DIRECTION_45::UNDEFINED ) m_direction = m_lastSegDirection; return m_direction; diff --git a/pcbnew/router/pns_line_placer.h b/pcbnew/router/pns_line_placer.h index 37f56f4726..e660c12a3d 100644 --- a/pcbnew/router/pns_line_placer.h +++ b/pcbnew/router/pns_line_placer.h @@ -95,6 +95,8 @@ public: void SetDisabled( bool aDisabled = true ) { m_disabled = aDisabled; } + bool IsManuallyForced() const { return m_manuallyForced; } + private: SHAPE_LINE_CHAIN m_trail; int m_tolerance; diff --git a/pcbnew/router/pns_optimizer.cpp b/pcbnew/router/pns_optimizer.cpp index d507ba25fb..66a5823831 100644 --- a/pcbnew/router/pns_optimizer.cpp +++ b/pcbnew/router/pns_optimizer.cpp @@ -931,7 +931,7 @@ int OPTIMIZER::smartPadsSingle( LINE* aLine, ITEM* aPad, bool aEnd, int aEndVert DIRECTION_45 dir_bkout( breakout.CSegment( -1 ) ); - if(!connect.SegmentCount()) + if( !connect.SegmentCount() ) continue; int ang1 = dir_bkout.Angle( DIRECTION_45( connect.CSegment( 0 ) ) ); diff --git a/pcbnew/router/pns_solid.h b/pcbnew/router/pns_solid.h index e9d68aa884..c20e1dc54d 100644 --- a/pcbnew/router/pns_solid.h +++ b/pcbnew/router/pns_solid.h @@ -39,6 +39,7 @@ public: { m_movable = false; m_padToDie = 0; + m_orientation = 0; } ~SOLID() @@ -130,12 +131,16 @@ public: m_offset = aOffset; } + double GetOrientation() const { return m_orientation; } + void SetOrientation( double aOrientation ) { m_orientation = aOrientation; } + private: VECTOR2I m_pos; SHAPE* m_shape; SHAPE* m_alternateShape; VECTOR2I m_offset; int m_padToDie; + double m_orientation; // in 1/10 degrees, matching PAD }; }