diff --git a/pcbnew/router/pns_dp_meander_placer.cpp b/pcbnew/router/pns_dp_meander_placer.cpp index 2a2d165a70..70c15f63f5 100644 --- a/pcbnew/router/pns_dp_meander_placer.cpp +++ b/pcbnew/router/pns_dp_meander_placer.cpp @@ -141,22 +141,8 @@ void DP_MEANDER_PLACER::release() long long int DP_MEANDER_PLACER::origPathLength() const { - long long int totalP = m_padToDieLength; - long long int totalN = m_padToDieLength; - - for( const ITEM* item : m_tunedPathP.CItems() ) - { - if( const LINE* l = dyn_cast( item ) ) - totalP += l->CLine().Length(); - - } - - for( const ITEM* item : m_tunedPathN.CItems() ) - { - if( const LINE* l = dyn_cast( item ) ) - totalN += l->CLine().Length(); - } - + long long int totalP = m_padToDieLength + lineLength( m_tunedPathP ); + long long int totalN = m_padToDieLength + lineLength( m_tunedPathN ); return std::max( totalP, totalN ); } diff --git a/pcbnew/router/pns_meander_placer.cpp b/pcbnew/router/pns_meander_placer.cpp index 98b4e9400c..022bd74d0c 100644 --- a/pcbnew/router/pns_meander_placer.cpp +++ b/pcbnew/router/pns_meander_placer.cpp @@ -97,27 +97,7 @@ bool MEANDER_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem ) long long int MEANDER_PLACER::origPathLength() const { - long long int total = m_padToDieLength; - - for( int idx = 0; idx < m_tunedPath.Size(); idx++ ) - { - const ITEM* item = m_tunedPath[idx]; - - if( const LINE* l = dyn_cast( item ) ) - { - total += l->CLine().Length(); - } - else if( item->OfKind( ITEM::VIA_T ) && idx > 0 && idx < m_tunedPath.Size() - 1 ) - { - int layerPrev = m_tunedPath[idx - 1]->Layer(); - int layerNext = m_tunedPath[idx + 1]->Layer(); - - if( layerPrev != layerNext ) - total += m_router->GetInterface()->StackupHeight( layerPrev, layerNext ); - } - } - - return total; + return m_padToDieLength + lineLength( m_tunedPath ); } diff --git a/pcbnew/router/pns_meander_placer_base.cpp b/pcbnew/router/pns_meander_placer_base.cpp index 7d666395dd..a134c4b2b8 100644 --- a/pcbnew/router/pns_meander_placer_base.cpp +++ b/pcbnew/router/pns_meander_placer_base.cpp @@ -260,4 +260,30 @@ VECTOR2I MEANDER_PLACER_BASE::getSnappedStartPoint( LINKED_ITEM* aStartItem, VEC } } + +long long int MEANDER_PLACER_BASE::lineLength( const ITEM_SET& aLine ) const +{ + long long int total = 0; + + for( int idx = 0; idx < aLine.Size(); idx++ ) + { + const ITEM* item = aLine[idx]; + + if( const LINE* l = dyn_cast( item ) ) + { + total += l->CLine().Length(); + } + else if( item->OfKind( ITEM::VIA_T ) && idx > 0 && idx < aLine.Size() - 1 ) + { + int layerPrev = aLine[idx - 1]->Layer(); + int layerNext = aLine[idx + 1]->Layer(); + + if( layerPrev != layerNext ) + total += m_router->GetInterface()->StackupHeight( layerPrev, layerNext ); + } + } + + return total; +} + } diff --git a/pcbnew/router/pns_meander_placer_base.h b/pcbnew/router/pns_meander_placer_base.h index 3796ba3fe9..51fa7ea9a7 100644 --- a/pcbnew/router/pns_meander_placer_base.h +++ b/pcbnew/router/pns_meander_placer_base.h @@ -137,6 +137,13 @@ protected: VECTOR2I getSnappedStartPoint( LINKED_ITEM* aStartItem, VECTOR2I aStartPoint ); + /** + * Calculate the total length of the line represented by an item set (tracks and vias) + * @param aLine + * @return + */ + long long int lineLength( const ITEM_SET& aLine ) const; + ///< Pointer to world to search colliding items. NODE* m_world; diff --git a/pcbnew/router/pns_meander_skew_placer.cpp b/pcbnew/router/pns_meander_skew_placer.cpp index 746d48b01f..7d8d91780f 100644 --- a/pcbnew/router/pns_meander_skew_placer.cpp +++ b/pcbnew/router/pns_meander_skew_placer.cpp @@ -111,12 +111,12 @@ bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem ) if ( m_originPair.PLine().Net() == m_originLine.Net() ) { m_padToDieLength = m_padToDieN; - m_coupledLength = itemsetLength( m_tunedPathN ); + m_coupledLength = lineLength( m_tunedPathN ); } else { m_padToDieLength = m_padToDieP; - m_coupledLength = itemsetLength( m_tunedPathP ); + m_coupledLength = lineLength( m_tunedPathP ); } return true; @@ -125,22 +125,7 @@ bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem ) long long int MEANDER_SKEW_PLACER::origPathLength() const { - return itemsetLength ( m_tunedPath ); -} - - -long long int MEANDER_SKEW_PLACER::itemsetLength( const ITEM_SET& aSet ) const -{ - long long int total = m_padToDieLength; - for( const ITEM* item : aSet.CItems() ) - { - if( const LINE* l = dyn_cast( item ) ) - { - total += l->CLine().Length(); - } - } - - return total; + return lineLength( m_tunedPath ); } diff --git a/pcbnew/router/pns_meander_skew_placer.h b/pcbnew/router/pns_meander_skew_placer.h index fd8e020f43..1e0e213c2b 100644 --- a/pcbnew/router/pns_meander_skew_placer.h +++ b/pcbnew/router/pns_meander_skew_placer.h @@ -53,7 +53,6 @@ public: private: long long int currentSkew() const; - long long int itemsetLength( const ITEM_SET& aSet ) const; long long int origPathLength() const override;