46#define AR_KEEPOUT_MARGIN  500 
   47#define AR_ABORT_PLACEMENT -1 
   52#define CELL_IS_EMPTY  0x00 
   53#define CELL_IS_HOLE   0x01    
   54#define CELL_IS_MODULE 0x02    
   55#define CELL_IS_EDGE   0x20    
   56#define CELL_IS_FRIEND 0x40    
   57#define CELL_IS_ZONE   0x80    
  113    for( 
auto drawing : 
m_board->Drawings() )
 
  115        switch( drawing->Type() )
 
 
  144    std::vector <int> x_coordinates;
 
  157    for( 
int refy = rect.
GetY(), endy = rect.
GetBottom(); refy < endy; refy += step )
 
  160        int idy = (refy - coord_orgin.
y) / step;
 
  171        x_coordinates.clear();
 
  173        for( 
int v = 0; v < outline.
PointCount(); v++ )
 
  175            int seg_startX = outline.
CPoint( v ).
x;
 
  176            int seg_startY = outline.
CPoint( v ).
y;
 
  177            int seg_endX   = outline.
CPoint( v + 1 ).
x;
 
  178            int seg_endY   = outline.
CPoint( v + 1 ).
y;
 
  181            if( ( seg_startY > refy ) && ( seg_endY > refy ) )
 
  185            if( ( seg_startY <= refy ) && (seg_endY <= refy ) )
 
  195            seg_endX -= seg_startX;
 
  196            seg_endY -= seg_startY;
 
  197            double newrefy = (double) ( refy - seg_startY );
 
  211            double inv_slope = (double) seg_endX / seg_endY;
 
  212            intersec_x = newrefy * inv_slope;
 
  213            x_coordinates.push_back( (
int) intersec_x + seg_startX );
 
  220        std::sort( x_coordinates.begin(), x_coordinates.end() );
 
  224        if( ( x_coordinates.size() & 1 ) != 0 )
 
  231        int iimax = x_coordinates.size() - 1;
 
  233        for( 
int ii = 0; ii < iimax; ii += 2 )
 
  235            int seg_start_x = x_coordinates[ii] - coord_orgin.
x;
 
  236            int seg_end_x = x_coordinates[ii + 1] - coord_orgin.
x;
 
  241            for( 
int idx = seg_start_x / step; idx < 
m_matrix.m_Ncols; idx++ )
 
  243                if( idx * step > seg_end_x )
 
  246                if( idx * step >= seg_start_x )
 
 
  259    if( aLayerMask[ 
F_Cu ] )
 
  268    if( aLayerMask[ 
B_Cu ] )
 
 
  332        int margin = (
m_matrix.m_GridRouting / 2) + 
pad->GetOwnClearance( 
pad->GetLayer() );
 
 
  353    if( ox > 
m_matrix.m_BrdBox.GetRight() )
 
  359    if( fx > 
m_matrix.m_BrdBox.GetRight() )
 
  365    if( oy > 
m_matrix.m_BrdBox.GetBottom() )
 
  371    if( fy > 
m_matrix.m_BrdBox.GetBottom() )
 
  380    m_matrix.TraceFilledRectangle( ox, oy, fx, fy, layerMask,
 
  386        int margin = (
m_matrix.m_GridRouting / 2) + 
pad->GetOwnClearance( 
pad->GetLayer() );
 
 
  412    start   -= 
m_matrix.m_BrdBox.GetOrigin();
 
  415    int row_min = start.
y / 
m_matrix.m_GridRouting;
 
  417    int col_min = start.
x / 
m_matrix.m_GridRouting;
 
  420    if( start.
y > row_min * 
m_matrix.m_GridRouting )
 
  423    if( start.
x > col_min * 
m_matrix.m_GridRouting )
 
  429    if( row_max >= ( 
m_matrix.m_Nrows - 1 ) )
 
  435    if( col_max >= ( 
m_matrix.m_Ncols - 1 ) )
 
  438    for( 
int row = row_min; row <= row_max; row++ )
 
  440        for( 
int col = col_min; col <= col_max; col++ )
 
  442            unsigned int data = 
m_matrix.GetCell( row, col, side );
 
 
  461    start   -= 
m_matrix.m_BrdBox.GetOrigin();
 
  464    int row_min = start.
y / 
m_matrix.m_GridRouting;
 
  466    int col_min = start.
x / 
m_matrix.m_GridRouting;
 
  469    if( start.
y > row_min * 
m_matrix.m_GridRouting )
 
  472    if( start.
x > col_min * 
m_matrix.m_GridRouting )
 
  478    if( row_max >= ( 
m_matrix.m_Nrows - 1 ) )
 
  484    if( col_max >= ( 
m_matrix.m_Ncols - 1 ) )
 
  487    unsigned int keepOutCost = 0;
 
  489    for( 
int row = row_min; row <= row_max; row++ )
 
  491        for( 
int col = col_min; col <= col_max; col++ )
 
  497            keepOutCost += 
m_matrix.GetDist( row, col, side );
 
 
  517    fpBBox.
Move( -1*aOffset );
 
 
  543    double  min_cost, curr_cost, Score;
 
  546    lastPosOK = 
m_matrix.m_BrdBox.GetOrigin();
 
  552    fpBBox.
Move( -fpPos );
 
  561    initialPos.
x    -= initialPos.
x % 
m_matrix.m_GridRouting;
 
  562    initialPos.
y    -= initialPos.
y % 
m_matrix.m_GridRouting;
 
  568    testOtherSide = 
false;
 
  570    if( 
m_matrix.m_RoutingLayersCount > 1 )
 
  576            if( !( 
pad->GetLayerSet() & other ).any() )
 
  579            testOtherSide = 
true;
 
  601            if( keepOutCost >= 0 )    
 
  606                Score       = curr_cost + keepOutCost;
 
  608                if( (min_cost >= Score ) || (min_cost < 0 ) )
 
 
  634    const PAD* nearest = 
nullptr;
 
  635    int64_t    nearestDist = INT64_MAX;
 
  639        if ( footprint == aRefFP )
 
  642        if( !
m_matrix.m_BrdBox.Contains( footprint->GetPosition() ) )
 
  645        for( 
PAD* 
pad: footprint->Pads() )
 
  653            if ( dist < nearestDist )
 
 
  689        dx  = 
end.x - start.
x;
 
  690        dy  = 
end.y - start.
y;
 
  704        double conn_cost = hypot( dx, dy * 2.0 );
 
  705        curr_cost += conn_cost;    
 
 
  736    std::vector<FOOTPRINT*> fpList;
 
  740        fpList.push_back( footprint );
 
  744    for( 
unsigned kk = 0; kk < fpList.size(); kk++ )
 
  757    for( 
unsigned kk = 0; kk < fpList.size(); kk++ )
 
  761        auto edges = 
m_connectivity->GetRatsnestForComponent( footprint, 
true );
 
  763        footprint->
SetFlag( edges.size() ) ;
 
  772    for( 
unsigned ii = 0; ii < fpList.size(); ii++ )
 
  779        altFootprint = footprint;
 
  781        if( footprint->
GetFlag() == 0 )
 
  784        bestFootprint = footprint;
 
  789        return bestFootprint;
 
 
  828                                              bool aPlaceOffboardModules )
 
  832    bool     cancelled = 
false;
 
  849        footprint->SetNeedsPlaced( 
false );
 
  851    std::vector<FOOTPRINT*> offboardMods;
 
  853    if( aPlaceOffboardModules )
 
  857            if( !
m_matrix.m_BrdBox.Contains( footprint->GetPosition() ) )
 
  858                offboardMods.push_back( footprint );
 
  862    for( 
FOOTPRINT* footprint : aFootprints )
 
  864        footprint->SetNeedsPlaced( 
true );
 
  865        aCommit->
Modify( footprint );
 
  868    for( 
FOOTPRINT* footprint : offboardMods )
 
  870        footprint->SetNeedsPlaced( 
true );
 
  871        aCommit->
Modify( footprint );
 
  876        if( footprint->NeedsPlaced() )    
 
 
#define AR_KEEPOUT_MARGIN
 
static bool sortFootprintsByRatsnestSize(FOOTPRINT *ref, FOOTPRINT *compare)
 
#define AR_ABORT_PLACEMENT
 
static bool sortFootprintsByComplexity(FOOTPRINT *ref, FOOTPRINT *compare)
 
constexpr EDA_IU_SCALE pcbIUScale
 
std::function< int(FOOTPRINT *aFootprint)> m_refreshCallback
 
std::unique_ptr< CONNECTIVITY_DATA > m_connectivity
 
void drawPlacementRoutingMatrix()
 
int getOptimalFPPlacement(FOOTPRINT *aFootprint)
 
AR_RESULT AutoplaceFootprints(std::vector< FOOTPRINT * > &aFootprints, BOARD_COMMIT *aCommit, bool aPlaceOffboardModules=false)
 
int testRectangle(const BOX2I &aRect, int side)
 
SHAPE_POLY_SET m_fpAreaTop
 
bool fillMatrix()
Fill m_matrix cells from m_boardShape.
 
AR_AUTOPLACER(BOARD *aBoard)
 
PROGRESS_REPORTER * m_progressReporter
 
const PAD * nearestPad(FOOTPRINT *aRefFP, PAD *aRefPad, const VECTOR2I &aOffset)
 
void buildFpAreas(FOOTPRINT *aFootprint, int aFpClearance)
 
unsigned int calculateKeepOutArea(const BOX2I &aRect, int side)
 
void placeFootprint(FOOTPRINT *aFootprint, bool aDoNotRecreateRatsnest, const VECTOR2I &aPos)
 
FOOTPRINT * pickFootprint()
Find the "best" footprint place.
 
void genModuleOnRoutingMatrix(FOOTPRINT *aFootprint)
 
SHAPE_POLY_SET m_topFreeArea
 
void addPad(PAD *aPad, int aClearance)
 
void addFpBody(const VECTOR2I &aStart, const VECTOR2I &aEnd, const LSET &aLayerMask)
 
int testFootprintOnBoard(FOOTPRINT *aFootprint, bool TstOtherSide, const VECTOR2I &aOffset)
 
SHAPE_POLY_SET m_fpAreaBottom
 
double computePlacementRatsnestCost(FOOTPRINT *aFootprint, const VECTOR2I &aOffset)
 
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
 
SHAPE_POLY_SET m_boardShape
 
int genPlacementRoutingMatrix()
 
SHAPE_POLY_SET m_bottomFreeArea
 
unsigned char MATRIX_CELL
 
BASE_SET & set(size_t pos)
 
Information pertinent to a Pcbnew printed circuit board.
 
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
 
constexpr const Vec GetEnd() const
 
constexpr void SetOrigin(const Vec &pos)
 
constexpr coord_type GetY() const
 
constexpr size_type GetWidth() const
 
constexpr coord_type GetX() const
 
constexpr size_type GetHeight() const
 
constexpr coord_type GetLeft() const
 
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
 
constexpr const Vec & GetOrigin() const
 
constexpr coord_type GetRight() const
 
constexpr coord_type GetTop() const
 
constexpr coord_type GetBottom() const
 
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
 
A color representation with 4 components: red, green, blue, alpha.
 
LSET is a set of PCB_LAYER_IDs.
 
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
 
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
 
VECTOR2I GetPosition() const override
 
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
 
int PointCount() const
Return the number of points (vertices) in this line chain.
 
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
 
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
 
Represent a set of closed polygons.
 
void Fracture()
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
 
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
 
int OutlineCount() const
Return the number of outlines in the set.
 
This file is part of the common library.
 
Message panel definition file.
 
Class that computes missing connections on a PCB.
 
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
 
VECTOR2< int32_t > VECTOR2I