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 
73  void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
74  {
75  m_overlay = aOverlay;
76  }
77 
78  void SetRefreshCallback( std::function<int()> aCallback )
79  {
80  m_refreshCallback = aCallback;
81  }
82 
84  {
85  m_progressReporter = aReporter;
86  }
87 
88 private:
90  void rotateModule( MODULE* module, double angle, bool incremental );
92  void genModuleOnRoutingMatrix( MODULE* Module );
93  int propagate();
94  int testRectangle( const EDA_RECT& aRect, int side );
95  unsigned int calculateKeepOutArea( const EDA_RECT& aRect, int side );
96  int testModuleOnBoard( MODULE* aModule, bool TstOtherSide, const wxPoint& aOffset );
97  int getOptimalModulePlacement( MODULE* aModule );
98  double computePlacementRatsnestCost( MODULE* aModule, const wxPoint& aOffset );
99  MODULE* pickModule();
100  void placeModule( MODULE* aModule, bool aDoNotRecreateRatsnest, const wxPoint& aPos );
101  const D_PAD* nearestPad( MODULE* aRefModule, D_PAD* aRefPad, const wxPoint& aOffset );
102 
104 
106 
109  double m_minCost;
111 
112  std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
113  std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
114  std::function<int()> m_refreshCallback;
116 };
117 
118 #endif
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)
int propagate()
Function propagate Used only in autoplace calculations Uses the routing matrix to fill the cells with...
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)
wxPoint m_moduleOffset
void SetOverlay(std::shared_ptr< KIGFX::VIEW_OVERLAY > aOverlay)
Definition: ar_autoplacer.h:73
void SetRefreshCallback(std::function< int()> aCallback)
Definition: ar_autoplacer.h:78
const D_PAD * nearestPad(MODULE *aRefModule, D_PAD *aRefPad, const wxPoint &aOffset)
void genModuleOnRoutingMatrix(MODULE *Module)
AR_MATRIX m_matrix
void drawPlacementRoutingMatrix()
const std::vector< MODULE * > QueryOffboardModules()
int getOptimalModulePlacement(MODULE *aModule)
double computePlacementRatsnestCost(MODULE *aModule, const wxPoint &aOffset)
int genPlacementRoutingMatrix()
void SetPlacementGrid(int aGrid)
Definition: ar_autoplacer.h:68
MODULE * pickModule()
Function Module find the "best" module place The criteria are:
AR_RESULT
Definition: ar_autoplacer.h:49
unsigned int calculateKeepOutArea(const EDA_RECT &aRect, int side)
int testModuleOnBoard(MODULE *aModule, bool TstOtherSide, const wxPoint &aOffset)
int testRectangle(const EDA_RECT &aRect, int side)
AR_AUTOPLACER(BOARD *aBoard)
std::function< int()> m_refreshCallback
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Definition: ar_autoplacer.h:83
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
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