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
38
39#include <view/view_overlay.h>
40
42{
45 AR_FREE_CELL = 0
46};
47
49{
53};
54
56
58{
59public:
60 AR_AUTOPLACER( BOARD* aBoard );
61
62 AR_RESULT AutoplaceFootprints( std::vector<FOOTPRINT*>& aFootprints, BOARD_COMMIT* aCommit,
63 bool aPlaceOffboardModules = false );
64
68 void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
69 {
70 m_overlay = aOverlay;
71 }
72
76 void SetRefreshCallback( std::function<int( FOOTPRINT* aFootprint )> aCallback )
77 {
78 m_refreshCallback = aCallback;
79 }
80
82 {
83 m_progressReporter = aReporter;
84 }
85
86private:
87 void drawPlacementRoutingMatrix(); // draw the working area (shows free and occupied areas)
89
95 bool fillMatrix();
96 void genModuleOnRoutingMatrix( FOOTPRINT* aFootprint );
97
98 int testRectangle( const BOX2I& aRect, int side );
99 unsigned int calculateKeepOutArea( const BOX2I& aRect, int side );
100 int testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide, const VECTOR2I& aOffset );
101 int getOptimalFPPlacement( FOOTPRINT* aFootprint );
102 double computePlacementRatsnestCost( FOOTPRINT* aFootprint, const VECTOR2I& aOffset );
103
110
111 void placeFootprint( FOOTPRINT* aFootprint, bool aDoNotRecreateRatsnest, const VECTOR2I& aPos );
112
113 const PAD* nearestPad( FOOTPRINT* aRefFP, PAD* aRefPad, const VECTOR2I& aOffset );
114
115 // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
116 void addFpBody( const VECTOR2I& aStart, const VECTOR2I& aEnd, LSET aLayerMask );
117
118 // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
119 void addPad( PAD* aPad, int aClearance );
120
121 // Build m_fpAreaTop and m_fpAreaBottom polygonal shapes for aFootprint.
122 // aFpClearance is a mechanical clearance.
123 void buildFpAreas( FOOTPRINT* aFootprint, int aFpClearance );
124
126 SHAPE_POLY_SET m_topFreeArea; // The polygonal description of the top side free areas;
127 SHAPE_POLY_SET m_bottomFreeArea; // The polygonal description of the bottom side free areas;
128 SHAPE_POLY_SET m_boardShape; // The polygonal description of the board;
129 SHAPE_POLY_SET m_fpAreaTop; // The polygonal description of the footprint to place,
130 // top side;
131 SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place,
132 // bottom side;
133
135
137 double m_minCost;
139
140 std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
141 std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
142 std::function<int( FOOTPRINT* aFootprint )> m_refreshCallback;
144};
145
146#endif
AR_RESULT
Definition: ar_autoplacer.h:49
@ AR_COMPLETED
Definition: ar_autoplacer.h:50
@ AR_FAILURE
Definition: ar_autoplacer.h:52
@ AR_CANCELLED
Definition: ar_autoplacer.h:51
AR_CELL_STATE
Definition: ar_autoplacer.h:42
@ AR_FREE_CELL
Definition: ar_autoplacer.h:45
@ AR_OCCUIPED_BY_MODULE
Definition: ar_autoplacer.h:44
@ AR_OUT_OF_BOARD
Definition: ar_autoplacer.h:43
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:68
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:76
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:81
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:48
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:574
Definition: pad.h:59
A progress reporter interface for use in multi-threaded environments.
Represent a set of closed polygons.