KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ar_autoplacer.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
7 *
8 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24
25#ifndef __AR_AUTOPLACER_H
26#define __AR_AUTOPLACER_H
27
28#include "ar_matrix.h"
29
30#include <lset.h>
31
33
34#include <view/view_overlay.h>
35
42
49
51
53{
54public:
55 AR_AUTOPLACER( BOARD* aBoard );
56
57 AR_RESULT AutoplaceFootprints( std::vector<FOOTPRINT*>& aFootprints, BOARD_COMMIT* aCommit,
58 bool aPlaceOffboardModules = false );
59
63 void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
64 {
65 m_overlay = aOverlay;
66 }
67
71 void SetRefreshCallback( std::function<int( FOOTPRINT* aFootprint )> aCallback )
72 {
73 m_refreshCallback = aCallback;
74 }
75
77 {
78 m_progressReporter = aReporter;
79 }
80
81private:
82 void drawPlacementRoutingMatrix(); // draw the working area (shows free and occupied areas)
84
90 bool fillMatrix();
91 void genModuleOnRoutingMatrix( FOOTPRINT* aFootprint );
92
93 int testRectangle( const BOX2I& aRect, int side );
94 unsigned int calculateKeepOutArea( const BOX2I& aRect, int side );
95 int testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide, const VECTOR2I& aOffset );
96 int getOptimalFPPlacement( FOOTPRINT* aFootprint );
97 double computePlacementRatsnestCost( FOOTPRINT* aFootprint, const VECTOR2I& aOffset );
98
105
106 void placeFootprint( FOOTPRINT* aFootprint, bool aDoNotRecreateRatsnest, const VECTOR2I& aPos );
107
108 const PAD* nearestPad( FOOTPRINT* aRefFP, PAD* aRefPad, const VECTOR2I& aOffset );
109
110 // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
111 void addFpBody( const VECTOR2I& aStart, const VECTOR2I& aEnd, const LSET& aLayerMask );
112
113 // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
114 void addPad( PAD* aPad, int aClearance );
115
116 // Build m_fpAreaTop and m_fpAreaBottom polygonal shapes for aFootprint.
117 // aFpClearance is a mechanical clearance.
118 void buildFpAreas( FOOTPRINT* aFootprint, int aFpClearance );
119
121 SHAPE_POLY_SET m_topFreeArea; // The polygonal description of the top side free areas;
122 SHAPE_POLY_SET m_bottomFreeArea; // The polygonal description of the bottom side free areas;
123 SHAPE_POLY_SET m_boardShape; // The polygonal description of the board;
124 SHAPE_POLY_SET m_fpAreaTop; // The polygonal description of the footprint to place,
125 // top side;
126 SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place,
127 // bottom side;
128
130
132 double m_minCost;
134
135 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
136 std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
137 std::function<int( FOOTPRINT* aFootprint )> m_refreshCallback;
139};
140
141#endif
AR_RESULT
@ AR_COMPLETED
@ AR_FAILURE
@ AR_CANCELLED
AR_CELL_STATE
@ AR_FREE_CELL
@ AR_OCCUIPED_BY_MODULE
@ AR_OUT_OF_BOARD
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
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)
void SetOverlay(std::shared_ptr< KIGFX::VIEW_OVERLAY > aOverlay)
Set a VIEW overlay to draw items during a autoplace session.
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)
void SetRefreshCallback(std::function< int(FOOTPRINT *aFootprint)> aCallback)
Callback to redraw on screen the view after changes, for instance after moving a footprint.
int testFootprintOnBoard(FOOTPRINT *aFootprint, bool TstOtherSide, const VECTOR2I &aOffset)
AR_MATRIX m_matrix
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
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
VECTOR2I m_curPosition
int genPlacementRoutingMatrix()
SHAPE_POLY_SET m_bottomFreeArea
Handle the matrix routing that describes the actual board.
Definition ar_matrix.h:45
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Definition pad.h:61
A progress reporter interface for use in multi-threaded environments.
Represent a set of closed polygons.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683