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 (C) 1992-2021 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, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28
29#ifndef __AR_AUTOPLACER_H
30#define __AR_AUTOPLACER_H
31
32#include "ar_matrix.h"
33
34#include <board.h>
35#include <footprint.h>
36#include <lset.h>
37
39
40#include <view/view_overlay.h>
41
43{
46 AR_FREE_CELL = 0
47};
48
50{
54};
55
57
59{
60public:
61 AR_AUTOPLACER( BOARD* aBoard );
62
63 AR_RESULT AutoplaceFootprints( std::vector<FOOTPRINT*>& aFootprints, BOARD_COMMIT* aCommit,
64 bool aPlaceOffboardModules = false );
65
69 void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
70 {
71 m_overlay = aOverlay;
72 }
73
77 void SetRefreshCallback( std::function<int( FOOTPRINT* aFootprint )> aCallback )
78 {
79 m_refreshCallback = aCallback;
80 }
81
83 {
84 m_progressReporter = aReporter;
85 }
86
87private:
88 void drawPlacementRoutingMatrix(); // draw the working area (shows free and occupied areas)
90
96 bool fillMatrix();
97 void genModuleOnRoutingMatrix( FOOTPRINT* aFootprint );
98
99 int testRectangle( const BOX2I& aRect, int side );
100 unsigned int calculateKeepOutArea( const BOX2I& aRect, int side );
101 int testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide, const VECTOR2I& aOffset );
102 int getOptimalFPPlacement( FOOTPRINT* aFootprint );
103 double computePlacementRatsnestCost( FOOTPRINT* aFootprint, const VECTOR2I& aOffset );
104
111
112 void placeFootprint( FOOTPRINT* aFootprint, bool aDoNotRecreateRatsnest, const VECTOR2I& aPos );
113
114 const PAD* nearestPad( FOOTPRINT* aRefFP, PAD* aRefPad, const VECTOR2I& aOffset );
115
116 // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
117 void addFpBody( const VECTOR2I& aStart, const VECTOR2I& aEnd, LSET aLayerMask );
118
119 // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
120 void addPad( PAD* aPad, int aClearance );
121
122 // Build m_fpAreaTop and m_fpAreaBottom polygonal shapes for aFootprint.
123 // aFpClearance is a mechanical clearance.
124 void buildFpAreas( FOOTPRINT* aFootprint, int aFpClearance );
125
127 SHAPE_POLY_SET m_topFreeArea; // The polygonal description of the top side free areas;
128 SHAPE_POLY_SET m_bottomFreeArea; // The polygonal description of the bottom side free areas;
129 SHAPE_POLY_SET m_boardShape; // The polygonal description of the board;
130 SHAPE_POLY_SET m_fpAreaTop; // The polygonal description of the footprint to place,
131 // top side;
132 SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place,
133 // bottom side;
134
136
138 double m_minCost;
140
141 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
142 std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
143 std::function<int( FOOTPRINT* aFootprint )> m_refreshCallback;
145};
146
147#endif
AR_RESULT
Definition: ar_autoplacer.h:50
@ AR_COMPLETED
Definition: ar_autoplacer.h:51
@ AR_FAILURE
Definition: ar_autoplacer.h:53
@ AR_CANCELLED
Definition: ar_autoplacer.h:52
AR_CELL_STATE
Definition: ar_autoplacer.h:43
@ AR_FREE_CELL
Definition: ar_autoplacer.h:46
@ AR_OCCUIPED_BY_MODULE
Definition: ar_autoplacer.h:45
@ AR_OUT_OF_BOARD
Definition: ar_autoplacer.h:44
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.
Definition: ar_autoplacer.h:69
SHAPE_POLY_SET m_fpAreaTop
bool fillMatrix()
Fill m_matrix cells from m_boardShape.
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 SetRefreshCallback(std::function< int(FOOTPRINT *aFootprint)> aCallback)
Callback to redraw on screen the view after changes, for instance after moving a footprint.
Definition: ar_autoplacer.h:77
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)
Definition: ar_autoplacer.h:82
VECTOR2I m_curPosition
int genPlacementRoutingMatrix()
SHAPE_POLY_SET m_bottomFreeArea
void addFpBody(const VECTOR2I &aStart, const VECTOR2I &aEnd, LSET aLayerMask)
Handle the matrix routing that describes the actual board.
Definition: ar_matrix.h:49
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
Definition: pad.h:54
A progress reporter interface for use in multi-threaded environments.
Represent a set of closed polygons.