KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
LENGTH_CALCULATION Class Reference

Class which calculates lengths (and associated routing statistics) in a BOARD context. More...

#include <length_calculation.h>

Public Member Functions

 LENGTH_CALCULATION (BOARD *aBoard)
 Construct the calculator in the given BOARD context.
 
int64_t CalculateLength (std::vector< LENGTH_CALCULATION_ITEM > &aItems, PATH_OPTIMISATIONS aOptimisations, const PAD *aStartPad=nullptr, const PAD *aEndPad=nullptr) const
 Calculates the electrical length of the given items.
 
LENGTH_DETAILS CalculateLengthDetails (std::vector< LENGTH_CALCULATION_ITEM > &aItems, PATH_OPTIMISATIONS aOptimisations, const PAD *aStartPad=nullptr, const PAD *aEndPad=nullptr, bool aWithLayerLengths=false) const
 Calculates the electrical length of the given items.
 
LENGTH_CALCULATION_ITEM GetLengthCalculationItem (BOARD_CONNECTED_ITEM *aBoardItem) const
 Return a LENGTH_CALCULATION_ITEM constructed from the given BOARD_CONNECTED_ITEM.
 

Static Public Member Functions

static void OptimiseTraceInPad (SHAPE_LINE_CHAIN &aLine, const PAD *aPad, PCB_LAYER_ID aPcbLayer)
 Optimises the given trace / line to minimise the electrical path length within the given pad.
 

Protected Types

enum class  MERGE_POINT { START , END }
 Enum to describe whether track merging is attempted from the start or end of a track segment. More...
 

Protected Member Functions

int stackupHeight (PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSecondLayer) const
 Returns the stackup distance between the two given layers.
 
void inferViaInPad (const PAD *aPad, const LENGTH_CALCULATION_ITEM &aItem, LENGTH_DETAILS &aDetails) const
 Infers if there is a via in the given pad.
 

Static Protected Member Functions

static void optimiseTracesInPads (const std::vector< LENGTH_CALCULATION_ITEM * > &aPads, const std::vector< LENGTH_CALCULATION_ITEM * > &aLines)
 Optimises the given set of items to minimise the electrical path length.
 
static void clipLineToPad (SHAPE_LINE_CHAIN &aLine, const PAD *aPad, PCB_LAYER_ID aLayer, bool aForward=true)
 Clips the given line to the minimal direct electrical length within the pad.
 
static void optimiseViaLayers (const std::vector< LENGTH_CALCULATION_ITEM * > &aVias, std::vector< LENGTH_CALCULATION_ITEM * > &aLines, std::map< VECTOR2I, std::unordered_set< LENGTH_CALCULATION_ITEM * > > &aLinesPositionMap, const std::map< VECTOR2I, std::unordered_set< LENGTH_CALCULATION_ITEM * > > &aPadsPositionMap)
 Optimises the via layers.
 
static void mergeLines (std::vector< LENGTH_CALCULATION_ITEM * > &aLines, std::map< VECTOR2I, std::unordered_set< LENGTH_CALCULATION_ITEM * > > &aLinesPositionMap)
 Merges any lines (traces) that are contiguous, on one layer, and with no junctions.
 
static void mergeShapeLineChains (SHAPE_LINE_CHAIN &aPrimary, const SHAPE_LINE_CHAIN &aSecondary, MERGE_POINT aMergePoint)
 Merges two SHAPE_LINE_CHAINs where there is a shared endpoing.
 

Protected Attributes

BOARDm_board
 The parent board for all items.
 

Detailed Description

Class which calculates lengths (and associated routing statistics) in a BOARD context.

Definition at line 192 of file length_calculation.h.

Member Enumeration Documentation

◆ MERGE_POINT

enum class LENGTH_CALCULATION::MERGE_POINT
strongprotected

Enum to describe whether track merging is attempted from the start or end of a track segment.

Enumerator
START 
END 

Definition at line 233 of file length_calculation.h.

Constructor & Destructor Documentation

◆ LENGTH_CALCULATION()

LENGTH_CALCULATION::LENGTH_CALCULATION ( BOARD aBoard)
inlineexplicit

Construct the calculator in the given BOARD context.

Definition at line 196 of file length_calculation.h.

Member Function Documentation

◆ CalculateLength()

int64_t LENGTH_CALCULATION::CalculateLength ( std::vector< LENGTH_CALCULATION_ITEM > &  aItems,
PATH_OPTIMISATIONS  aOptimisations,
const PAD aStartPad = nullptr,
const PAD aEndPad = nullptr 
) const

Calculates the electrical length of the given items.

Parameters
aItemsis the vector of items making up the route
aPathTypeindicates whether this is an ordered route, or an unordered collection
aOptimisedindicates whether this has been optimised for electrical length (e.g. clipping within pads)
aStartPadis the starting pad of the route
aEndPadis the ending pad of the route

Definition at line 228 of file length_calculation.cpp.

References CalculateLengthDetails(), and LENGTH_DETAILS::TotalLength().

Referenced by PNS_KICAD_IFACE_BASE::CalculateRoutedPathLength().

◆ CalculateLengthDetails()

LENGTH_DETAILS LENGTH_CALCULATION::CalculateLengthDetails ( std::vector< LENGTH_CALCULATION_ITEM > &  aItems,
PATH_OPTIMISATIONS  aOptimisations,
const PAD aStartPad = nullptr,
const PAD aEndPad = nullptr,
bool  aWithLayerLengths = false 
) const

Calculates the electrical length of the given items.

Parameters
aItemsis the vector of items making up the route
aPathTypeindicates whether this is an ordered route, or an unordered collection
aOptimisedindicates whether this has been optimised for electrical length (e.g. clipping within pads)
aStartPadis the starting pad of the route
aEndPadis the ending pad of the route
aWithLayerLengthsindicates whether the layer length structure should be populated

Definition at line 109 of file length_calculation.cpp.

References BOARD::GetDesignSettings(), PATH_OPTIMISATIONS::InferViaInPad, inferViaInPad(), LENGTH_DETAILS::LayerLengths, m_board, BOARD_DESIGN_SETTINGS::m_UseHeightForLengthCalcs, LENGTH_CALCULATION_ITEM::MERGED_RETIRED, mergeLines(), PATH_OPTIMISATIONS::MergeTracks, LENGTH_DETAILS::NumPads, LENGTH_DETAILS::NumVias, PATH_OPTIMISATIONS::OptimiseTracesInPads, optimiseTracesInPads(), PATH_OPTIMISATIONS::OptimiseViaLayers, optimiseViaLayers(), LENGTH_DETAILS::PadToDieLength, stackupHeight(), LENGTH_DETAILS::TrackLength, and LENGTH_DETAILS::ViaLength.

Referenced by CalculateLength(), and BOARD::GetTrackLength().

◆ clipLineToPad()

void LENGTH_CALCULATION::clipLineToPad ( SHAPE_LINE_CHAIN aLine,
const PAD aPad,
PCB_LAYER_ID  aLayer,
bool  aForward = true 
)
staticprotected

◆ GetLengthCalculationItem()

◆ inferViaInPad()

void LENGTH_CALCULATION::inferViaInPad ( const PAD aPad,
const LENGTH_CALCULATION_ITEM aItem,
LENGTH_DETAILS aDetails 
) const
protected

Infers if there is a via in the given pad.

Adds via details to the length details data structure if found.

Definition at line 208 of file length_calculation.cpp.

References B_Cu, LSET::Contains(), F_Cu, LENGTH_CALCULATION_ITEM::GetStartLayer(), PADSTACK::LayerSet(), LENGTH_DETAILS::NumVias, PAD::Padstack(), stackupHeight(), LENGTH_CALCULATION_ITEM::Type(), and LENGTH_DETAILS::ViaLength.

Referenced by CalculateLengthDetails().

◆ mergeLines()

void LENGTH_CALCULATION::mergeLines ( std::vector< LENGTH_CALCULATION_ITEM * > &  aLines,
std::map< VECTOR2I, std::unordered_set< LENGTH_CALCULATION_ITEM * > > &  aLinesPositionMap 
)
staticprotected

◆ mergeShapeLineChains()

void LENGTH_CALCULATION::mergeShapeLineChains ( SHAPE_LINE_CHAIN aPrimary,
const SHAPE_LINE_CHAIN aSecondary,
MERGE_POINT  aMergePoint 
)
staticprotected

Merges two SHAPE_LINE_CHAINs where there is a shared endpoing.

aSecondary is merged in to aPrimary

Definition at line 334 of file length_calculation.cpp.

References SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::CLastPoint(), SHAPE_LINE_CHAIN::CPoints(), SHAPE_LINE_CHAIN::GetPoint(), SHAPE_LINE_CHAIN::Insert(), and START.

Referenced by mergeLines().

◆ OptimiseTraceInPad()

void LENGTH_CALCULATION::OptimiseTraceInPad ( SHAPE_LINE_CHAIN aLine,
const PAD aPad,
PCB_LAYER_ID  aPcbLayer 
)
static

Optimises the given trace / line to minimise the electrical path length within the given pad.

Definition at line 474 of file length_calculation.cpp.

References SHAPE_LINE_CHAIN::CLastPoint(), clipLineToPad(), SHAPE_LINE_CHAIN::CPoint(), ERROR_INSIDE, PAD::FlashLayer(), PAD::GetEffectivePolygon(), and PAD::GetPosition().

Referenced by PNS::TOPOLOGY::AssembleTuningPath(), and optimiseTracesInPads().

◆ optimiseTracesInPads()

void LENGTH_CALCULATION::optimiseTracesInPads ( const std::vector< LENGTH_CALCULATION_ITEM * > &  aPads,
const std::vector< LENGTH_CALCULATION_ITEM * > &  aLines 
)
staticprotected

Optimises the given set of items to minimise the electrical path length.

At the moment only optimises lines attached to pads, future work could optimise paths through pads

Assumes that any polylines are only connected at either end, and not at midpoints

Definition at line 370 of file length_calculation.cpp.

References LENGTH_CALCULATION_ITEM::MERGED_IN_USE, OptimiseTraceInPad(), and pad.

Referenced by CalculateLengthDetails().

◆ optimiseViaLayers()

void LENGTH_CALCULATION::optimiseViaLayers ( const std::vector< LENGTH_CALCULATION_ITEM * > &  aVias,
std::vector< LENGTH_CALCULATION_ITEM * > &  aLines,
std::map< VECTOR2I, std::unordered_set< LENGTH_CALCULATION_ITEM * > > &  aLinesPositionMap,
const std::map< VECTOR2I, std::unordered_set< LENGTH_CALCULATION_ITEM * > > &  aPadsPositionMap 
)
staticprotected

Optimises the via layers.

Ensures that vias that are routed through only on one layer do not count towards total length calculations.

Definition at line 392 of file length_calculation.cpp.

References LSET::Contains(), LSET::CuStack(), LENGTH_CALCULATION_ITEM::GetPad(), LENGTH_CALCULATION_ITEM::GetStartLayer(), PADSTACK::LayerSet(), PAD::Padstack(), BASE_SET::set(), UNDEFINED_LAYER, and via.

Referenced by CalculateLengthDetails().

◆ stackupHeight()

int LENGTH_CALCULATION::stackupHeight ( PCB_LAYER_ID  aFirstLayer,
PCB_LAYER_ID  aSecondLayer 
) const
protected

Returns the stackup distance between the two given layers.

Note: Can return 0 if the board design settings disallow stackup height calculations

Definition at line 236 of file length_calculation.cpp.

References BOARD_STACKUP::BuildDefaultStackupList(), BOARD::GetCopperLayerCount(), BOARD::GetDesignSettings(), BOARD_STACKUP::GetLayerDistance(), BOARD_DESIGN_SETTINGS::GetStackupDescriptor(), m_board, BOARD_DESIGN_SETTINGS::m_HasStackup, and BOARD_DESIGN_SETTINGS::m_UseHeightForLengthCalcs.

Referenced by CalculateLengthDetails(), and inferViaInPad().

Member Data Documentation

◆ m_board

BOARD* LENGTH_CALCULATION::m_board
protected

The parent board for all items.

Definition at line 230 of file length_calculation.h.

Referenced by CalculateLengthDetails(), GetLengthCalculationItem(), and stackupHeight().


The documentation for this class was generated from the following files: