2018-08-24 10:54:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2021-07-26 19:35:12 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
|
2018-08-24 10:54:45 +00:00
|
|
|
*
|
2021-07-26 19:35:12 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-08-24 10:54:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __AR_AUTOPLACER_H
|
|
|
|
#define __AR_AUTOPLACER_H
|
|
|
|
|
|
|
|
#include "ar_matrix.h"
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
#include <view/view_overlay.h>
|
|
|
|
|
|
|
|
enum AR_CELL_STATE
|
|
|
|
{
|
|
|
|
AR_OUT_OF_BOARD = -2,
|
|
|
|
AR_OCCUIPED_BY_MODULE = -1,
|
|
|
|
AR_FREE_CELL = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AR_RESULT
|
|
|
|
{
|
|
|
|
AR_COMPLETED = 1,
|
|
|
|
AR_CANCELLED,
|
|
|
|
AR_FAILURE
|
|
|
|
};
|
|
|
|
|
|
|
|
class PROGRESS_REPORTER;
|
|
|
|
|
|
|
|
class AR_AUTOPLACER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AR_AUTOPLACER( BOARD* aBoard );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
AR_RESULT AutoplaceFootprints( std::vector<FOOTPRINT*>& aFootprints, BOARD_COMMIT* aCommit,
|
2020-11-13 01:12:36 +00:00
|
|
|
bool aPlaceOffboardModules = false );
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
/**
|
|
|
|
* Set a VIEW overlay to draw items during a autoplace session.
|
|
|
|
*/
|
2018-08-24 10:54:45 +00:00
|
|
|
void SetOverlay( std::shared_ptr<KIGFX::VIEW_OVERLAY> aOverlay )
|
|
|
|
{
|
|
|
|
m_overlay = aOverlay;
|
|
|
|
}
|
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
/**
|
2021-07-26 19:35:12 +00:00
|
|
|
* Callback to redraw on screen the view after changes, for instance after moving a footprint.
|
2018-12-15 16:50:42 +00:00
|
|
|
*/
|
2020-11-13 15:15:52 +00:00
|
|
|
void SetRefreshCallback( std::function<int( FOOTPRINT* aFootprint )> aCallback )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
|
|
|
m_refreshCallback = aCallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetProgressReporter( PROGRESS_REPORTER* aReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter = aReporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-11-13 15:15:52 +00:00
|
|
|
void drawPlacementRoutingMatrix(); // draw the working area (shows free and occupied areas)
|
|
|
|
int genPlacementRoutingMatrix();
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
/**
|
|
|
|
* Fill m_matrix cells from m_boardShape.
|
|
|
|
*
|
|
|
|
* Cells inside m_boardShape are set to CELL_IS_ZONE.
|
2018-12-15 16:50:42 +00:00
|
|
|
*/
|
2020-11-13 15:15:52 +00:00
|
|
|
bool fillMatrix();
|
|
|
|
void genModuleOnRoutingMatrix( FOOTPRINT* aFootprint );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2022-08-31 22:57:24 +00:00
|
|
|
int testRectangle( const BOX2I& aRect, int side );
|
|
|
|
unsigned int calculateKeepOutArea( const BOX2I& aRect, int side );
|
2022-01-01 06:04:08 +00:00
|
|
|
int testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide, const VECTOR2I& aOffset );
|
2020-11-13 15:15:52 +00:00
|
|
|
int getOptimalFPPlacement( FOOTPRINT* aFootprint );
|
2022-01-01 06:04:08 +00:00
|
|
|
double computePlacementRatsnestCost( FOOTPRINT* aFootprint, const VECTOR2I& aOffset );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-13 02:57:11 +00:00
|
|
|
* Find the "best" footprint place. The criteria are:
|
2020-10-21 03:48:06 +00:00
|
|
|
* - Maximum ratsnest with footprints already placed
|
2018-12-15 16:50:42 +00:00
|
|
|
* - Max size, and number of pads max
|
|
|
|
*/
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* pickFootprint();
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
void placeFootprint( FOOTPRINT* aFootprint, bool aDoNotRecreateRatsnest, const VECTOR2I& aPos );
|
2020-11-13 01:12:36 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
const PAD* nearestPad( FOOTPRINT* aRefFP, PAD* aRefPad, const VECTOR2I& aOffset );
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
|
2022-01-01 06:04:08 +00:00
|
|
|
void addFpBody( const VECTOR2I& aStart, const VECTOR2I& aEnd, LSET aLayerMask );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
// Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
|
2020-11-12 22:30:02 +00:00
|
|
|
void addPad( PAD* aPad, int aClearance );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
// Build m_fpAreaTop and m_fpAreaBottom polygonal shapes for aFootprint.
|
|
|
|
// aFpClearance is a mechanical clearance.
|
2020-11-13 15:15:52 +00:00
|
|
|
void buildFpAreas( FOOTPRINT* aFootprint, int aFpClearance );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
AR_MATRIX m_matrix;
|
2018-12-15 16:50:42 +00:00
|
|
|
SHAPE_POLY_SET m_topFreeArea; // The polygonal description of the top side free areas;
|
|
|
|
SHAPE_POLY_SET m_bottomFreeArea; // The polygonal description of the bottom side free areas;
|
|
|
|
SHAPE_POLY_SET m_boardShape; // The polygonal description of the board;
|
2021-07-26 19:35:12 +00:00
|
|
|
SHAPE_POLY_SET m_fpAreaTop; // The polygonal description of the footprint to place,
|
|
|
|
// top side;
|
|
|
|
SHAPE_POLY_SET m_fpAreaBottom; // The polygonal description of the footprint to place,
|
|
|
|
// bottom side;
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
BOARD* m_board;
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I m_curPosition;
|
|
|
|
double m_minCost;
|
|
|
|
int m_gridSize;
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::shared_ptr<KIGFX::VIEW_OVERLAY> m_overlay;
|
|
|
|
std::unique_ptr<CONNECTIVITY_DATA> m_connectivity;
|
|
|
|
std::function<int( FOOTPRINT* aFootprint )> m_refreshCallback;
|
|
|
|
PROGRESS_REPORTER* m_progressReporter;
|
2018-08-24 10:54:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|