45#define AR_KEEPOUT_MARGIN 500
46#define AR_ABORT_PLACEMENT -1
51#define CELL_IS_EMPTY 0x00
52#define CELL_IS_HOLE 0x01
53#define CELL_IS_MODULE 0x02
54#define CELL_IS_EDGE 0x20
55#define CELL_IS_FRIEND 0x40
56#define CELL_IS_ZONE 0x80
114 switch( drawing->Type() )
141 std::vector <int> x_coordinates;
154 for(
int refy = rect.
GetY(), endy = rect.
GetBottom(); refy < endy; refy += step )
157 int idy = (refy - coord_orgin.
y) / step;
168 x_coordinates.clear();
170 for(
int v = 0; v < outline.
PointCount(); v++ )
172 int seg_startX = outline.
CPoint( v ).
x;
173 int seg_startY = outline.
CPoint( v ).
y;
174 int seg_endX = outline.
CPoint( v + 1 ).
x;
175 int seg_endY = outline.
CPoint( v + 1 ).
y;
178 if( ( seg_startY > refy ) && ( seg_endY > refy ) )
182 if( ( seg_startY <= refy ) && (seg_endY <= refy ) )
192 seg_endX -= seg_startX;
193 seg_endY -= seg_startY;
194 double newrefy = (double) ( refy - seg_startY );
208 double inv_slope = (double) seg_endX / seg_endY;
209 intersec_x = newrefy * inv_slope;
210 x_coordinates.push_back( (
int) intersec_x + seg_startX );
217 std::sort( x_coordinates.begin(), x_coordinates.end() );
221 if( ( x_coordinates.size() & 1 ) != 0 )
228 int iimax = x_coordinates.size() - 1;
230 for(
int ii = 0; ii < iimax; ii += 2 )
232 int seg_start_x = x_coordinates[ii] - coord_orgin.
x;
233 int seg_end_x = x_coordinates[ii + 1] - coord_orgin.
x;
240 if( idx * step > seg_end_x )
243 if( idx * step >= seg_start_x )
256 if( aLayerMask[
F_Cu ] )
265 if( aLayerMask[
B_Cu ] )
314 layerMask.set(
F_Cu );
317 layerMask.set(
B_Cu );
372 layerMask.set(
F_Cu );
375 layerMask.set(
B_Cu );
435 for(
int row = row_min; row <= row_max; row++ )
437 for(
int col = col_min; col <= col_max; col++ )
484 unsigned int keepOutCost = 0;
486 for(
int row = row_min; row <= row_max; row++ )
488 for(
int col = col_min; col <= col_max; col++ )
514 fpBBox.
Move( -1*aOffset );
544 double min_cost, curr_cost, Score;
553 fpBBox.
Move( -fpPos );
569 testOtherSide =
false;
577 if( !(
pad->GetLayerSet() & other ).any() )
580 testOtherSide =
true;
602 if( keepOutCost >= 0 )
607 Score = curr_cost + keepOutCost;
609 if( (min_cost >= Score ) || (min_cost < 0 ) )
635 const PAD* nearest =
nullptr;
636 int64_t nearestDist = INT64_MAX;
640 if ( footprint == aRefFP )
646 for(
PAD*
pad: footprint->Pads() )
654 if ( dist < nearestDist )
690 dx = end.
x - start.
x;
691 dy = end.
y - start.
y;
705 double conn_cost = hypot( dx, dy * 2.0 );
706 curr_cost += conn_cost;
737 std::vector<FOOTPRINT*> fpList;
741 fpList.push_back( footprint );
745 for(
unsigned kk = 0; kk < fpList.size(); kk++ )
758 for(
unsigned kk = 0; kk < fpList.size(); kk++ )
762 auto edges =
m_connectivity->GetRatsnestForComponent( footprint,
true );
764 footprint->
SetFlag( edges.size() ) ;
773 for(
unsigned ii = 0; ii < fpList.size(); ii++ )
780 altFootprint = footprint;
782 if( footprint->
GetFlag() == 0 )
785 bestFootprint = footprint;
790 return bestFootprint;
829 bool aPlaceOffboardModules )
833 bool cancelled =
false;
850 footprint->SetNeedsPlaced(
false );
852 std::vector<FOOTPRINT*> offboardMods;
854 if( aPlaceOffboardModules )
859 offboardMods.push_back( footprint );
863 for(
FOOTPRINT* footprint : aFootprints )
865 footprint->SetNeedsPlaced(
true );
866 aCommit->
Modify( footprint );
869 for(
FOOTPRINT* footprint : offboardMods )
871 footprint->SetNeedsPlaced(
true );
872 aCommit->
Modify( footprint );
877 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)
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
void addFpBody(const VECTOR2I &aStart, const VECTOR2I &aEnd, LSET aLayerMask)
void UnInitRoutingMatrix()
unsigned char MATRIX_CELL
void TraceSegmentPcb(PCB_SHAPE *aShape, int aColor, int aMargin, AR_MATRIX::CELL_OP op_logic)
void SetCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
PCB_LAYER_ID m_routeLayerBottom
int InitRoutingMatrix()
Initialize the data structures.
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
bool ComputeMatrixSize(const BOX2I &aBoundingBox)
Calculate the number of rows and columns of dimensions of aPcb for routing and automatic calculation ...
DIST_CELL GetDist(int aRow, int aCol, int aSide)
MATRIX_CELL GetCell(int aRow, int aCol, int aSide)
VECTOR2I GetBrdCoordOrigin()
void TraceFilledRectangle(int ux0, int uy0, int ux1, int uy1, double angle, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
void CreateKeepOutRectangle(int ux0, int uy0, int ux1, int uy1, int marge, int aKeepOut, LSET aLayerMask)
Function CreateKeepOutRectangle builds the cost map: Cells ( in Dist map ) inside the rect x0,...
void PlacePad(PAD *aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic)
PCB_LAYER_ID m_routeLayerTop
Information pertinent to a Pcbnew printed circuit board.
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
const BOX2I GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
const FOOTPRINTS & Footprints() const
const DRAWINGS & Drawings() const
void SetOrigin(const Vec &pos)
const Vec & GetOrigin() const
size_type GetHeight() const
coord_type GetTop() const
size_type GetWidth() const
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
bool Contains(const Vec &aPoint) const
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
coord_type GetRight() const
coord_type GetLeft() const
coord_type GetBottom() const
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
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
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void SetTitle(const wxString &aTitle)=0
Change the title displayed on the window caption.
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
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 RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET CloneDropTriangulation() const
This file is part of the common library.
Message panel definition file.
Class that computes missing connections on a PCB.
constexpr int mmToIU(double mm) const
double EuclideanNorm(const VECTOR2I &vector)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers