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_cell.h"
33 #include "ar_matrix.h"
34 
35 #include <class_board.h>
36 #include <class_module.h>
37 
39 
40 #include <view/view_overlay.h>
41 
43 {
47 };
48 
50 {
54 };
55 
56 class PROGRESS_REPORTER;
57 
59 {
60 public:
61  AR_AUTOPLACER( BOARD* aBoard );
62 
63  AR_RESULT AutoplaceModules( std::vector<MODULE*> aModules, BOARD_COMMIT* aCommit,
64  bool aPlaceOffboardModules = false );
65 
66  const std::vector<MODULE*> QueryOffboardModules();
67 
68  void SetPlacementGrid( int aGrid )
69  {
70  m_gridSize = aGrid;
71  }
72 
76  void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
77  {
78  m_overlay = aOverlay;
79  }
80 
85  void SetRefreshCallback( std::function<int( MODULE* aModule )> aCallback )
86  {
87  m_refreshCallback = aCallback;
88  }
89 
91  {
92  m_progressReporter = aReporter;
93  }
94 
95 private:
96  void drawPlacementRoutingMatrix(); // draw the working area (shows free and occupied areas)
97  void rotateModule( MODULE* module, double angle, bool incremental );
99 
103  bool fillMatrix();
104  void genModuleOnRoutingMatrix( MODULE* Module );
105 
106  int testRectangle( const EDA_RECT& aRect, int side );
107  int testModuleByPolygon( MODULE* aModule,int aSide, const wxPoint& aOffset );
108  unsigned int calculateKeepOutArea( const EDA_RECT& aRect, int side );
109  int testModuleOnBoard( MODULE* aModule, bool TstOtherSide, const wxPoint& aOffset );
110  int getOptimalModulePlacement( MODULE* aModule );
111  double computePlacementRatsnestCost( MODULE* aModule, const wxPoint& aOffset );
112 
118  MODULE* pickModule();
119 
120  void placeModule( MODULE* aModule, bool aDoNotRecreateRatsnest, const wxPoint& aPos );
121  const D_PAD* nearestPad( MODULE* aRefModule, D_PAD* aRefPad, const wxPoint& aOffset );
122 
123  // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
124  void addFpBody( wxPoint aStart, wxPoint aEnd, LSET aLayerMask );
125 
126  // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
127  void addPad( D_PAD* aPad, int aClearance );
128 
129  // Build m_fpAreaTop and m_fpAreaBottom polygonal shapes for aFootprint.
130  // aFpClearance is a mechanical clearance.
131  void buildFpAreas( MODULE* aFootprint, int aFpClearance );
132 
134  SHAPE_POLY_SET m_topFreeArea; // The polygonal description of the top side free areas;
135  SHAPE_POLY_SET m_bottomFreeArea; // The polygonal description of the bottom side free areas;
136  SHAPE_POLY_SET m_boardShape; // The polygonal description of the board;
137  SHAPE_POLY_SET m_fpAreaTop; // The polygonal description of the footprint to place, top side;
138  SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place, bottom side;
139 
141 
142  wxPoint m_curPosition;
143  wxPoint m_moduleOffset;
144  double m_minCost;
146 
147  std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
148  std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
149  std::function<int( MODULE* aModule )> m_refreshCallback;
151 };
152 
153 #endif
SHAPE_POLY_SET m_topFreeArea
void rotateModule(MODULE *module, double angle, bool incremental)
class AR_MATRIX handle the matrix routing that describes the actual board
Definition: ar_matrix.h:49
PROGRESS_REPORTER * m_progressReporter
void placeModule(MODULE *aModule, bool aDoNotRecreateRatsnest, const wxPoint &aPos)
A progress reporter for use in multi-threaded environments.
Class BOARD to handle a board.
AR_RESULT AutoplaceModules(std::vector< MODULE * > aModules, BOARD_COMMIT *aCommit, bool aPlaceOffboardModules=false)
void buildFpAreas(MODULE *aFootprint, int aFpClearance)
wxPoint m_moduleOffset
void addPad(D_PAD *aPad, int aClearance)
void SetOverlay(std::shared_ptr< KIGFX::VIEW_OVERLAY > aOverlay)
Set a VIEW overlay to draw items during a autoplace session.
Definition: ar_autoplacer.h:76
const D_PAD * nearestPad(MODULE *aRefModule, D_PAD *aRefPad, const wxPoint &aOffset)
void genModuleOnRoutingMatrix(MODULE *Module)
AR_MATRIX m_matrix
SHAPE_POLY_SET m_fpAreaBottom
void drawPlacementRoutingMatrix()
const std::vector< MODULE * > QueryOffboardModules()
Class LSET is a set of PCB_LAYER_IDs.
int getOptimalModulePlacement(MODULE *aModule)
SHAPE_POLY_SET m_boardShape
double computePlacementRatsnestCost(MODULE *aModule, const wxPoint &aOffset)
int genPlacementRoutingMatrix()
Class SHAPE_POLY_SET.
void SetPlacementGrid(int aGrid)
Definition: ar_autoplacer.h:68
MODULE * pickModule()
Find the "best" module place.
SHAPE_POLY_SET m_bottomFreeArea
AR_RESULT
Definition: ar_autoplacer.h:49
SHAPE_POLY_SET m_fpAreaTop
unsigned int calculateKeepOutArea(const EDA_RECT &aRect, int side)
int testModuleOnBoard(MODULE *aModule, bool TstOtherSide, const wxPoint &aOffset)
void SetRefreshCallback(std::function< int(MODULE *aModule)> aCallback)
a callback function to redraw on screen the view after changes, for instance after moving a footprint...
Definition: ar_autoplacer.h:85
bool fillMatrix()
fills m_matrix cells from m_boardShape.
int testRectangle(const EDA_RECT &aRect, int side)
int testModuleByPolygon(MODULE *aModule, int aSide, const wxPoint &aOffset)
void addFpBody(wxPoint aStart, wxPoint aEnd, LSET aLayerMask)
AR_AUTOPLACER(BOARD *aBoard)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:171
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Definition: ar_autoplacer.h:90
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
std::function< int(MODULE *aModule)> m_refreshCallback
Module description (excepted pads)
wxPoint m_curPosition
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
AR_CELL_STATE
Definition: ar_autoplacer.h:42
std::unique_ptr< CONNECTIVITY_DATA > m_connectivity