KiCad PCB EDA Suite
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, jean-pierre.charras@ujf-grenoble.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
7  *
8  * Copyright (C) 1992-2012 KiCad Developers, see change_log.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 {
46 };
47 
49 {
53 };
54 
55 class PROGRESS_REPORTER;
56 
58 {
59 public:
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 
77  void SetRefreshCallback( std::function<int( FOOTPRINT* aFootprint )> aCallback )
78  {
79  m_refreshCallback = aCallback;
80  }
81 
83  {
84  m_progressReporter = aReporter;
85  }
86 
87 private:
88  void drawPlacementRoutingMatrix(); // draw the working area (shows free and occupied areas)
89  void rotateFootprint( FOOTPRINT* aFootprint, double angle, bool incremental );
91 
95  bool fillMatrix();
96  void genModuleOnRoutingMatrix( FOOTPRINT* aFootprint );
97 
98  int testRectangle( const EDA_RECT& aRect, int side );
99  unsigned int calculateKeepOutArea( const EDA_RECT& aRect, int side );
100  int testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide, const wxPoint& aOffset );
101  int getOptimalFPPlacement( FOOTPRINT* aFootprint );
102  double computePlacementRatsnestCost( FOOTPRINT* aFootprint, const wxPoint& aOffset );
103 
110 
111  void placeFootprint( FOOTPRINT* aFootprint, bool aDoNotRecreateRatsnest, const wxPoint& aPos );
112 
113  const PAD* nearestPad( FOOTPRINT* aRefFP, PAD* aRefPad, const wxPoint& aOffset );
114 
115  // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
116  void addFpBody( wxPoint aStart, wxPoint 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, top side;
130  SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place, bottom side;
131 
133 
134  wxPoint m_curPosition;
135  double m_minCost;
137 
138  std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
139  std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
140  std::function<int( FOOTPRINT* aFootprint )> m_refreshCallback;
142 };
143 
144 #endif
SHAPE_POLY_SET m_topFreeArea
AR_MATRIX handle the matrix routing that describes the actual board.
Definition: ar_matrix.h:49
PROGRESS_REPORTER * m_progressReporter
int getOptimalFPPlacement(FOOTPRINT *aFootprint)
void SetRefreshCallback(std::function< int(FOOTPRINT *aFootprint)> aCallback)
a callback function to redraw on screen the view after changes, for instance after moving a footprint
Definition: ar_autoplacer.h:77
A progress reporter for use in multi-threaded environments.
FOOTPRINT * pickFootprint()
Find the "best" footprint place.
void placeFootprint(FOOTPRINT *aFootprint, bool aDoNotRecreateRatsnest, const wxPoint &aPos)
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
AR_MATRIX m_matrix
SHAPE_POLY_SET m_fpAreaBottom
void drawPlacementRoutingMatrix()
LSET is a set of PCB_LAYER_IDs.
SHAPE_POLY_SET m_boardShape
int genPlacementRoutingMatrix()
SHAPE_POLY_SET.
const PAD * nearestPad(FOOTPRINT *aRefFP, PAD *aRefPad, const wxPoint &aOffset)
SHAPE_POLY_SET m_bottomFreeArea
AR_RESULT
Definition: ar_autoplacer.h:48
SHAPE_POLY_SET m_fpAreaTop
unsigned int calculateKeepOutArea(const EDA_RECT &aRect, int side)
void genModuleOnRoutingMatrix(FOOTPRINT *aFootprint)
bool fillMatrix()
fills m_matrix cells from m_boardShape.
int testFootprintOnBoard(FOOTPRINT *aFootprint, bool TstOtherSide, const wxPoint &aOffset)
void rotateFootprint(FOOTPRINT *aFootprint, double angle, bool incremental)
int testRectangle(const EDA_RECT &aRect, int side)
void addFpBody(wxPoint aStart, wxPoint aEnd, LSET aLayerMask)
AR_AUTOPLACER(BOARD *aBoard)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Definition: ar_autoplacer.h:82
void buildFpAreas(FOOTPRINT *aFootprint, int aFpClearance)
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_curPosition
Definition: pad.h:59
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
void addPad(PAD *aPad, int aClearance)
std::function< int(FOOTPRINT *aFootprint)> m_refreshCallback
AR_CELL_STATE
Definition: ar_autoplacer.h:41
AR_RESULT AutoplaceFootprints(std::vector< FOOTPRINT * > &aFootprints, BOARD_COMMIT *aCommit, bool aPlaceOffboardModules=false)
double computePlacementRatsnestCost(FOOTPRINT *aFootprint, const wxPoint &aOffset)
std::unique_ptr< CONNECTIVITY_DATA > m_connectivity