46 #define AR_KEEPOUT_MARGIN 500 47 #define AR_ABORT_PLACEMENT -1 49 #define STEP_AR_MM 1.0 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 134 switch( drawing->Type() )
161 std::vector <int> x_coordinates;
174 for(
int refy = rect.
GetY(), endy = rect.
GetBottom(); refy < endy; refy += step )
177 int idy = (refy - coord_orgin.y) / step;
188 x_coordinates.clear();
190 for(
int v = 0; v < outline.
PointCount(); v++ )
192 int seg_startX = outline.
CPoint( v ).
x;
193 int seg_startY = outline.
CPoint( v ).
y;
194 int seg_endX = outline.
CPoint( v + 1 ).
x;
195 int seg_endY = outline.
CPoint( v + 1 ).
y;
198 if( ( seg_startY > refy ) && ( seg_endY > refy ) )
202 if( ( seg_startY <= refy ) && (seg_endY <= refy ) )
212 seg_endX -= seg_startX;
213 seg_endY -= seg_startY;
214 double newrefy = (double) ( refy - seg_startY );
228 double inv_slope = (double) seg_endX / seg_endY;
229 intersec_x = newrefy * inv_slope;
230 x_coordinates.push_back( (
int) intersec_x + seg_startX );
237 std::sort( x_coordinates.begin(), x_coordinates.end() );
241 if( ( x_coordinates.size() & 1 ) != 0 )
248 int iimax = x_coordinates.size() - 1;
250 for(
int ii = 0; ii < iimax; ii += 2 )
252 int seg_start_x = x_coordinates[ii] - coord_orgin.x;
253 int seg_end_x = x_coordinates[ii + 1] - coord_orgin.x;
260 if( idx * step > seg_end_x )
263 if( idx * step >= seg_start_x )
275 if( aFootprint ==
nullptr )
291 if( aLayerMask[
F_Cu ] )
300 if( aLayerMask[
B_Cu ] )
349 layerMask.set(
F_Cu );
352 layerMask.set(
B_Cu );
407 layerMask.set(
F_Cu );
410 layerMask.set(
B_Cu );
442 wxPoint end = rect.
GetEnd();
470 for(
int row = row_min; row <= row_max; row++ )
472 for(
int col = col_min; col <= col_max; col++ )
491 wxPoint end = aRect.
GetEnd();
519 unsigned int keepOutCost = 0;
521 for(
int row = row_min; row <= row_max; row++ )
523 for(
int col = col_min; col <= col_max; col++ )
538 const wxPoint& aOffset )
549 fpBBox.
Move( -aOffset );
579 double min_cost, curr_cost, Score;
588 fpBBox.
Move( -fpPos );
604 testOtherSide =
false;
612 if( !(
pad->GetLayerSet() & other ).any() )
615 testOtherSide =
true;
637 if( keepOutCost >= 0 )
642 Score = curr_cost + keepOutCost;
644 if( (min_cost >= Score ) || (min_cost < 0 ) )
669 const PAD* nearest =
nullptr;
670 int64_t nearestDist = INT64_MAX;
674 if ( footprint == aRefFP )
680 for(
PAD*
pad: footprint->Pads() )
688 if ( dist < nearestDist )
724 dx = end.
x - start.
x;
725 dy = end.
y - start.
y;
739 double conn_cost = hypot( dx, dy * 2.0 );
740 curr_cost += conn_cost;
771 std::vector<FOOTPRINT*> fpList;
775 fpList.push_back( footprint );
779 for(
unsigned kk = 0; kk < fpList.size(); kk++ )
792 for(
unsigned kk = 0; kk < fpList.size(); kk++ )
796 auto edges =
m_connectivity->GetRatsnestForComponent( footprint,
true );
798 footprint->
SetFlag( edges.size() ) ;
807 for(
unsigned ii = 0; ii < fpList.size(); ii++ )
814 altFootprint = footprint;
816 if( footprint->
GetFlag() == 0 )
819 bestFootprint = footprint;
824 return bestFootprint;
863 bool aPlaceOffboardModules )
867 bool cancelled =
false;
884 footprint->SetNeedsPlaced(
false );
886 std::vector<FOOTPRINT*> offboardMods;
888 if( aPlaceOffboardModules )
893 offboardMods.push_back( footprint );
897 for(
FOOTPRINT* footprint : aFootprints )
899 footprint->SetNeedsPlaced(
true );
900 aCommit->
Modify( footprint );
903 for(
FOOTPRINT* footprint : offboardMods )
905 footprint->SetNeedsPlaced(
true );
906 aCommit->
Modify( footprint );
911 if( footprint->NeedsPlaced() )
947 double bestRotation = 0.0;
956 if( rotAllowed != 0 )
965 bestRotation = 1800.0;
979 if( rotAllowed != 0 )
988 bestRotation = 900.0;
1000 if( rotAllowed != 0 )
1009 bestRotation = 2700.0;
1025 bestRotation += initialOrient;
SHAPE_POLY_SET m_topFreeArea
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
int InitRoutingMatrix()
Initialize the data structures.
void Move(const wxPoint &aMoveVector)
Move the rectangle by the aMoveVector.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
PROGRESS_REPORTER * m_progressReporter
int getOptimalFPPlacement(FOOTPRINT *aFootprint)
This file is part of the common library.
const EDA_RECT GetBoardEdgesBoundingBox() const
Return the board bounding box calculated using exclusively the board edges (graphics on Edge....
Class that computes missing connections on a PCB.
void TraceFilledRectangle(int ux0, int uy0, int ux1, int uy1, double angle, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
void SetOrigin(const wxPoint &pos)
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,...
coord_type GetBottom() const
FOOTPRINT * pickFootprint()
Find the "best" footprint place.
void placeFootprint(FOOTPRINT *aFootprint, bool aDoNotRecreateRatsnest, const wxPoint &aPos)
int PointCount() const
Return the number of points (vertices) in this line chain.
#define AR_KEEPOUT_MARGIN
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetTitle(const wxString &aTitle)=0
Change the title displayed on the window caption.
bool Contains(const wxPoint &aPoint) const
void PlacePad(PAD *aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic)
void addFpBody(const wxPoint &aStart, const wxPoint &aEnd, LSET aLayerMask)
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
const wxPoint GetEnd() const
SHAPE_POLY_SET m_fpAreaBottom
void drawPlacementRoutingMatrix()
PCB_LAYER_ID m_routeLayerTop
LSET is a set of PCB_LAYER_IDs.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
SHAPE_POLY_SET m_boardShape
int genPlacementRoutingMatrix()
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
const wxPoint GetOrigin() const
FOOTPRINTS & Footprints()
MATRIX_CELL GetCell(int aRow, int aCol, int aSide)
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
#define AR_ABORT_PLACEMENT
const EDA_RECT GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
void SetCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
const PAD * nearestPad(FOOTPRINT *aRefFP, PAD *aRefPad, const wxPoint &aOffset)
void TraceSegmentPcb(PCB_SHAPE *aShape, int aColor, int aMargin, AR_MATRIX::CELL_OP op_logic)
SHAPE_POLY_SET m_bottomFreeArea
SHAPE_POLY_SET m_fpAreaTop
unsigned int calculateKeepOutArea(const EDA_RECT &aRect, int side)
void genModuleOnRoutingMatrix(FOOTPRINT *aFootprint)
static bool sortFootprintsByRatsnestSize(FOOTPRINT *ref, FOOTPRINT *compare)
int NewOutline()
Creates a new hole in a given outline.
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
bool fillMatrix()
Fill m_matrix cells from m_boardShape.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
int testFootprintOnBoard(FOOTPRINT *aFootprint, bool TstOtherSide, const wxPoint &aOffset)
void rotateFootprint(FOOTPRINT *aFootprint, double angle, bool incremental)
void UnInitRoutingMatrix()
int testRectangle(const EDA_RECT &aRect, int side)
AR_AUTOPLACER(BOARD *aBoard)
wxPoint GetPosition() const override
Information pertinent to a Pcbnew printed circuit board.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
wxPoint GetBrdCoordOrigin()
void buildFpAreas(FOOTPRINT *aFootprint, int aFpClearance)
Handle the component boundary box.
static const double OrientationPenalty[11]
static bool sortFootprintsByComplexity(FOOTPRINT *ref, FOOTPRINT *compare)
unsigned char MATRIX_CELL
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
bool ComputeMatrixSize(const EDA_RECT &aBoundingBox)
Calculate the number of rows and columns of dimensions of aPcb for routing and automatic calculation ...
Message panel definition file.
DIST_CELL GetDist(int aRow, int aCol, int aSide)
class PCB_SHAPE, a segment not on copper layers
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
static constexpr int Millimeter2iu(double mm)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
void addPad(PAD *aPad, int aClearance)
std::function< int(FOOTPRINT *aFootprint)> m_refreshCallback
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
AR_RESULT AutoplaceFootprints(std::vector< FOOTPRINT * > &aFootprints, BOARD_COMMIT *aCommit, bool aPlaceOffboardModules=false)
PCB_LAYER_ID m_routeLayerBottom
double computePlacementRatsnestCost(FOOTPRINT *aFootprint, const wxPoint &aOffset)
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
A color representation with 4 components: red, green, blue, alpha.
std::unique_ptr< CONNECTIVITY_DATA > m_connectivity