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 <class_board.h>
35 #include <class_module.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 AutoplaceModules( std::vector<MODULE*> aModules, 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( MODULE* aModule )> 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 rotateModule( MODULE* module, double angle, bool incremental );
91 
95  bool fillMatrix();
96  void genModuleOnRoutingMatrix( MODULE* Module );
97 
98  int testRectangle( const EDA_RECT& aRect, int side );
99  unsigned int calculateKeepOutArea( const EDA_RECT& aRect, int side );
100  int testModuleOnBoard( MODULE* aModule, bool TstOtherSide, const wxPoint& aOffset );
101  int getOptimalModulePlacement( MODULE* aModule );
102  double computePlacementRatsnestCost( MODULE* aModule, const wxPoint& aOffset );
103 
109  MODULE* pickModule();
110 
111  void placeModule( MODULE* aModule, bool aDoNotRecreateRatsnest, const wxPoint& aPos );
112  const D_PAD* nearestPad( MODULE* aRefModule, D_PAD* aRefPad, const wxPoint& aOffset );
113 
114  // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
115  void addFpBody( wxPoint aStart, wxPoint aEnd, LSET aLayerMask );
116 
117  // Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
118  void addPad( D_PAD* aPad, int aClearance );
119 
120  // Build m_fpAreaTop and m_fpAreaBottom polygonal shapes for aFootprint.
121  // aFpClearance is a mechanical clearance.
122  void buildFpAreas( MODULE* aFootprint, int aFpClearance );
123 
125  SHAPE_POLY_SET m_topFreeArea; // The polygonal description of the top side free areas;
126  SHAPE_POLY_SET m_bottomFreeArea; // The polygonal description of the bottom side free areas;
127  SHAPE_POLY_SET m_boardShape; // The polygonal description of the board;
128  SHAPE_POLY_SET m_fpAreaTop; // The polygonal description of the footprint to place, top side;
129  SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place, bottom side;
130 
132 
134  double m_minCost;
136 
137  std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
138  std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
139  std::function<int( MODULE* aModule )> m_refreshCallback;
141 };
142 
143 #endif
SHAPE_POLY_SET m_topFreeArea
void rotateModule(MODULE *module, double angle, bool incremental)
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.
AR_RESULT AutoplaceModules(std::vector< MODULE * > aModules, BOARD_COMMIT *aCommit, bool aPlaceOffboardModules=false)
void buildFpAreas(MODULE *aFootprint, int aFpClearance)
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:68
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()
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()
SHAPE_POLY_SET.
MODULE * pickModule()
Find the "best" module place.
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)
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:77
bool fillMatrix()
fills m_matrix cells from m_boardShape.
int testRectangle(const EDA_RECT &aRect, int side)
void addFpBody(wxPoint aStart, wxPoint aEnd, LSET aLayerMask)
AR_AUTOPLACER(BOARD *aBoard)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Definition: ar_autoplacer.h:82
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
std::function< int(MODULE *aModule)> m_refreshCallback
wxPoint m_curPosition
std::shared_ptr< KIGFX::VIEW_OVERLAY > m_overlay
AR_CELL_STATE
Definition: ar_autoplacer.h:41
std::unique_ptr< CONNECTIVITY_DATA > m_connectivity