2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
*
|
2020-08-18 14:17:16 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors.
|
2011-11-10 15:55:05 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <pcbnew.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-10-25 04:49:02 +00:00
|
|
|
#include <widgets/msgpanel.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <track.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <pad.h>
|
2018-08-24 10:54:45 +00:00
|
|
|
#include <board_commit.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2018-08-24 10:54:45 +00:00
|
|
|
#include <widgets/progress_reporter.h>
|
2019-12-05 13:43:55 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
#include "ar_autoplacer.h"
|
2019-12-05 13:43:55 +00:00
|
|
|
#include "ar_matrix.h"
|
|
|
|
#include <memory>
|
2020-06-16 18:15:14 +00:00
|
|
|
#include <ratsnest/ratsnest_data.h>
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
#define AR_GAIN 16
|
|
|
|
#define AR_KEEPOUT_MARGIN 500
|
|
|
|
#define AR_ABORT_PLACEMENT -1
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
#define STEP_AR_MM 1.0
|
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
/* Bits characterizing cell */
|
|
|
|
#define CELL_IS_EMPTY 0x00
|
|
|
|
#define CELL_IS_HOLE 0x01 /* a conducting hole or obstacle */
|
2020-11-13 11:17:15 +00:00
|
|
|
#define CELL_IS_MODULE 0x02 /* auto placement occupied by a footprint */
|
2020-06-15 19:50:20 +00:00
|
|
|
#define CELL_IS_EDGE 0x20 /* Area and auto-placement: limiting cell contour (Board, Zone) */
|
|
|
|
#define CELL_IS_FRIEND 0x40 /* Area and auto-placement: cell part of the net */
|
|
|
|
#define CELL_IS_ZONE 0x80 /* Area and auto-placement: cell available */
|
|
|
|
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
/* Penalty (cost) for CntRot90 and CntRot180:
|
|
|
|
* CntRot90 and CntRot180 are from 0 (rotation allowed) to 10 (rotation not allowed)
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
2018-08-24 10:54:45 +00:00
|
|
|
static const double OrientationPenalty[11] =
|
2009-11-12 15:43:38 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
2.0, // CntRot = 0 rotation prohibited
|
|
|
|
1.9, // CntRot = 1
|
|
|
|
1.8, // CntRot = 2
|
|
|
|
1.7, // CntRot = 3
|
|
|
|
1.6, // CntRot = 4
|
|
|
|
1.5, // CntRot = 5
|
|
|
|
1.4, // CntRot = 5
|
|
|
|
1.3, // CntRot = 7
|
|
|
|
1.2, // CntRot = 8
|
|
|
|
1.1, // CntRot = 9
|
|
|
|
1.0 // CntRot = 10 rotation authorized, no penalty
|
2007-08-10 19:14:51 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
AR_AUTOPLACER::AR_AUTOPLACER( BOARD* aBoard )
|
|
|
|
{
|
|
|
|
m_board = aBoard;
|
2019-12-05 13:43:55 +00:00
|
|
|
m_connectivity = std::make_unique<CONNECTIVITY_DATA>( );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
m_connectivity->Add( footprint );
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
m_gridSize = Millimeter2iu( STEP_AR_MM );
|
2018-08-24 10:54:45 +00:00
|
|
|
m_progressReporter = nullptr;
|
|
|
|
m_refreshCallback = nullptr;
|
2019-02-16 13:09:21 +00:00
|
|
|
m_minCost = 0.0;
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void AR_AUTOPLACER::placeFootprint( FOOTPRINT* aFootprint, bool aDoNotRecreateRatsnest,
|
2020-11-13 01:12:36 +00:00
|
|
|
const wxPoint& aPos )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
if( !aFootprint )
|
2018-08-24 10:54:45 +00:00
|
|
|
return;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->SetPosition( aPos );
|
|
|
|
m_connectivity->Update( aFootprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
int AR_AUTOPLACER::genPlacementRoutingMatrix()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
m_matrix.UnInitRoutingMatrix();
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
EDA_RECT bbox = m_board->GetBoardEdgesBoundingBox();
|
2011-12-13 20:42:42 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 )
|
|
|
|
return 0;
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
// Build the board shape
|
2020-11-20 13:55:10 +00:00
|
|
|
m_board->GetBoardPolygonOutlines( m_boardShape );
|
2018-12-15 16:50:42 +00:00
|
|
|
m_topFreeArea = m_boardShape;
|
|
|
|
m_bottomFreeArea = m_boardShape;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
m_matrix.ComputeMatrixSize( bbox );
|
|
|
|
int nbCells = m_matrix.m_Ncols * m_matrix.m_Nrows;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
// Choose the number of board sides.
|
|
|
|
m_matrix.m_RoutingLayersCount = 2;
|
|
|
|
m_matrix.InitRoutingMatrix();
|
2018-12-15 16:50:42 +00:00
|
|
|
m_matrix.m_routeLayerBottom = B_Cu;
|
2018-08-24 10:54:45 +00:00
|
|
|
m_matrix.m_routeLayerTop = F_Cu;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Fill (mark) the cells inside the board:
|
|
|
|
fillMatrix();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Other obstacles can be added here:
|
2018-08-24 10:54:45 +00:00
|
|
|
for( auto drawing : m_board->Drawings() )
|
|
|
|
{
|
|
|
|
switch( drawing->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2018-12-15 16:50:42 +00:00
|
|
|
if( drawing->GetLayer() != Edge_Cuts )
|
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
m_matrix.TraceSegmentPcb( (PCB_SHAPE*) drawing, CELL_IS_HOLE | CELL_IS_EDGE,
|
2018-12-15 16:50:42 +00:00
|
|
|
m_matrix.m_GridRouting, AR_MATRIX::WRITE_CELL );
|
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
break;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
// Initialize top layer. to the same value as the bottom layer
|
|
|
|
if( m_matrix.m_BoardSide[AR_SIDE_TOP] )
|
|
|
|
memcpy( m_matrix.m_BoardSide[AR_SIDE_TOP], m_matrix.m_BoardSide[AR_SIDE_BOTTOM],
|
|
|
|
nbCells * sizeof(AR_MATRIX::MATRIX_CELL) );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
bool AR_AUTOPLACER::fillMatrix()
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
std::vector <int> x_coordinates;
|
|
|
|
bool success = true;
|
|
|
|
int step = m_matrix.m_GridRouting;
|
|
|
|
wxPoint coord_orgin = m_matrix.GetBrdCoordOrigin(); // Board coordinate of matruix cell (0,0)
|
|
|
|
|
|
|
|
// Create a single board outline:
|
|
|
|
SHAPE_POLY_SET brd_shape = m_boardShape;
|
|
|
|
brd_shape.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
const SHAPE_LINE_CHAIN& outline = brd_shape.Outline(0);
|
|
|
|
const BOX2I& rect = outline.BBox();
|
|
|
|
|
|
|
|
// Creates the horizontal segments
|
|
|
|
// Calculate the y limits of the area
|
|
|
|
for( int refy = rect.GetY(), endy = rect.GetBottom(); refy < endy; refy += step )
|
|
|
|
{
|
2018-12-16 09:43:47 +00:00
|
|
|
// The row index (vertical position) of current line scan inside the placement matrix
|
|
|
|
int idy = (refy - coord_orgin.y) / step;
|
|
|
|
|
|
|
|
// Ensure we are still inside the placement matrix
|
|
|
|
if( idy >= m_matrix.m_Nrows )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Ensure we are inside the placement matrix
|
|
|
|
if( idy <= 0 )
|
|
|
|
continue;
|
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// find all intersection points of an infinite line with polyline sides
|
|
|
|
x_coordinates.clear();
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
for( int v = 0; v < outline.PointCount(); v++ )
|
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
int seg_startX = outline.CPoint( v ).x;
|
|
|
|
int seg_startY = outline.CPoint( v ).y;
|
|
|
|
int seg_endX = outline.CPoint( v + 1 ).x;
|
|
|
|
int seg_endY = outline.CPoint( v + 1 ).y;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
/* Trivial cases: skip if ref above or below the segment to test */
|
|
|
|
if( ( seg_startY > refy ) && ( seg_endY > refy ) )
|
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// segment below ref point, or its Y end pos on Y coordinate ref point: skip
|
|
|
|
if( ( seg_startY <= refy ) && (seg_endY <= refy ) )
|
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
/* at this point refy is between seg_startY and seg_endY
|
|
|
|
* see if an horizontal line at Y = refy is intersecting this segment
|
|
|
|
*/
|
|
|
|
// calculate the x position of the intersection of this segment and the
|
|
|
|
// infinite line this is more easier if we move the X,Y axis origin to
|
|
|
|
// the segment start point:
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
seg_endX -= seg_startX;
|
|
|
|
seg_endY -= seg_startY;
|
|
|
|
double newrefy = (double) ( refy - seg_startY );
|
|
|
|
double intersec_x;
|
|
|
|
|
|
|
|
if ( seg_endY == 0 ) // horizontal segment on the same line: skip
|
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Now calculate the x intersection coordinate of the horizontal line at
|
|
|
|
// y = newrefy and the segment from (0,0) to (seg_endX,seg_endY) with the
|
|
|
|
// horizontal line at the new refy position the line slope is:
|
|
|
|
// slope = seg_endY/seg_endX; and inv_slope = seg_endX/seg_endY
|
|
|
|
// and the x pos relative to the new origin is:
|
|
|
|
// intersec_x = refy/slope = refy * inv_slope
|
|
|
|
// Note: because horizontal segments are already tested and skipped, slope
|
|
|
|
// exists (seg_end_y not O)
|
|
|
|
double inv_slope = (double) seg_endX / seg_endY;
|
|
|
|
intersec_x = newrefy * inv_slope;
|
|
|
|
x_coordinates.push_back( (int) intersec_x + seg_startX );
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// A line scan is finished: build list of segments
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Sort intersection points by increasing x value:
|
|
|
|
// So 2 consecutive points are the ends of a segment
|
|
|
|
std::sort( x_coordinates.begin(), x_coordinates.end() );
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// An even number of coordinates is expected, because a segment has 2 ends.
|
|
|
|
// An if this algorithm always works, it must always find an even count.
|
|
|
|
if( ( x_coordinates.size() & 1 ) != 0 )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Fill cells having the same Y coordinate
|
|
|
|
int iimax = x_coordinates.size() - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
for( int ii = 0; ii < iimax; ii += 2 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
int seg_start_x = x_coordinates[ii] - coord_orgin.x;
|
|
|
|
int seg_end_x = x_coordinates[ii + 1] - coord_orgin.x;
|
|
|
|
// Fill cells at y coord = idy,
|
|
|
|
// and at x cood >= seg_start_x and <= seg_end_x
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
for( int idx = seg_start_x / step; idx < m_matrix.m_Ncols; idx++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
if( idx * step > seg_end_x )
|
|
|
|
break;
|
|
|
|
|
2018-12-16 09:43:47 +00:00
|
|
|
if( idx * step >= seg_start_x )
|
2018-12-15 16:50:42 +00:00
|
|
|
m_matrix.SetCell( idy, idx, AR_SIDE_BOTTOM, CELL_IS_ZONE );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2018-12-15 16:50:42 +00:00
|
|
|
} // End examine segments in one area
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void AR_AUTOPLACER::rotateFootprint( FOOTPRINT* aFootprint, double angle, bool incremental )
|
2018-12-15 16:50:42 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
if( aFootprint == NULL )
|
2018-12-15 16:50:42 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
if( incremental )
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->SetOrientation( aFootprint->GetOrientation() + angle );
|
2018-12-15 16:50:42 +00:00
|
|
|
else
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->SetOrientation( angle );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
m_board->GetConnectivity()->Update( aFootprint );
|
2018-12-15 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AR_AUTOPLACER::addFpBody( wxPoint aStart, wxPoint aEnd, LSET aLayerMask )
|
|
|
|
{
|
|
|
|
// Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
|
|
|
|
if( aLayerMask[ F_Cu ] )
|
|
|
|
{
|
|
|
|
m_fpAreaTop.NewOutline();
|
|
|
|
m_fpAreaTop.Append( aStart.x, aStart.y );
|
|
|
|
m_fpAreaTop.Append( aEnd.x, aStart.y );
|
|
|
|
m_fpAreaTop.Append( aEnd.x, aEnd.y );
|
|
|
|
m_fpAreaTop.Append( aStart.x, aEnd.y );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2018-12-15 16:50:42 +00:00
|
|
|
if( aLayerMask[ B_Cu ] )
|
|
|
|
{
|
|
|
|
m_fpAreaBottom.NewOutline();
|
|
|
|
m_fpAreaBottom.Append( aStart.x, aStart.y );
|
|
|
|
m_fpAreaBottom.Append( aEnd.x, aStart.y );
|
|
|
|
m_fpAreaBottom.Append( aEnd.x, aEnd.y );
|
|
|
|
m_fpAreaBottom.Append( aStart.x, aEnd.y );
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
void AR_AUTOPLACER::addPad( PAD* aPad, int aClearance )
|
2018-12-15 16:50:42 +00:00
|
|
|
{
|
|
|
|
// Add a polygonal shape (rectangle) to m_fpAreaFront and/or m_fpAreaBack
|
|
|
|
EDA_RECT bbox = aPad->GetBoundingBox();
|
|
|
|
bbox.Inflate( aClearance );
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
if( aPad->IsOnLayer( F_Cu ) )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
m_fpAreaTop.NewOutline();
|
|
|
|
m_fpAreaTop.Append( bbox.GetLeft(), bbox.GetTop() );
|
|
|
|
m_fpAreaTop.Append( bbox.GetRight(), bbox.GetTop() );
|
|
|
|
m_fpAreaTop.Append( bbox.GetRight(), bbox.GetBottom() );
|
|
|
|
m_fpAreaTop.Append( bbox.GetLeft(), bbox.GetBottom() );
|
|
|
|
}
|
|
|
|
if( aPad->IsOnLayer( B_Cu ) )
|
|
|
|
{
|
|
|
|
m_fpAreaBottom.NewOutline();
|
|
|
|
m_fpAreaBottom.Append( bbox.GetLeft(), bbox.GetTop() );
|
|
|
|
m_fpAreaBottom.Append( bbox.GetRight(), bbox.GetTop() );
|
|
|
|
m_fpAreaBottom.Append( bbox.GetRight(), bbox.GetBottom() );
|
|
|
|
m_fpAreaBottom.Append( bbox.GetLeft(), bbox.GetBottom() );
|
|
|
|
}
|
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void AR_AUTOPLACER::buildFpAreas( FOOTPRINT* aFootprint, int aFpClearance )
|
2018-12-15 16:50:42 +00:00
|
|
|
{
|
|
|
|
m_fpAreaTop.RemoveAllContours();
|
|
|
|
m_fpAreaBottom.RemoveAllContours();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
aFootprint->BuildPolyCourtyards();
|
|
|
|
m_fpAreaTop = aFootprint->GetPolyCourtyardFront();
|
|
|
|
m_fpAreaBottom = aFootprint->GetPolyCourtyardBack();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
LSET layerMask;
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
if( aFootprint->GetLayer() == F_Cu )
|
|
|
|
layerMask.set( F_Cu );
|
|
|
|
|
|
|
|
if( aFootprint->GetLayer() == B_Cu )
|
|
|
|
layerMask.set( B_Cu );
|
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
EDA_RECT fpBBox = aFootprint->GetBoundingBox();
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
fpBBox.Inflate( ( m_matrix.m_GridRouting / 2 ) + aFpClearance );
|
|
|
|
|
|
|
|
// Add a minimal area to the fp area:
|
|
|
|
addFpBody( fpBBox.GetOrigin(), fpBBox.GetEnd(), layerMask );
|
|
|
|
|
|
|
|
// Trace pads + clearance areas.
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2018-12-15 16:50:42 +00:00
|
|
|
{
|
2020-10-12 17:40:03 +00:00
|
|
|
int margin = (m_matrix.m_GridRouting / 2) + pad->GetOwnClearance( pad->GetLayer() );
|
2018-12-15 16:50:42 +00:00
|
|
|
addPad( pad, margin );
|
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void AR_AUTOPLACER::genModuleOnRoutingMatrix( FOOTPRINT* Module )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
|
|
|
int ox, oy, fx, fy;
|
|
|
|
LSET layerMask;
|
|
|
|
EDA_RECT fpBBox = Module->GetBoundingBox();
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
fpBBox.Inflate( m_matrix.m_GridRouting / 2 );
|
|
|
|
ox = fpBBox.GetX();
|
|
|
|
fx = fpBBox.GetRight();
|
|
|
|
oy = fpBBox.GetY();
|
|
|
|
fy = fpBBox.GetBottom();
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( ox < m_matrix.m_BrdBox.GetX() )
|
|
|
|
ox = m_matrix.m_BrdBox.GetX();
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( ox > m_matrix.m_BrdBox.GetRight() )
|
|
|
|
ox = m_matrix.m_BrdBox.GetRight();
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( fx < m_matrix.m_BrdBox.GetX() )
|
|
|
|
fx = m_matrix.m_BrdBox.GetX();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( fx > m_matrix.m_BrdBox.GetRight() )
|
|
|
|
fx = m_matrix.m_BrdBox.GetRight();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( oy < m_matrix.m_BrdBox.GetY() )
|
|
|
|
oy = m_matrix.m_BrdBox.GetY();
|
|
|
|
|
|
|
|
if( oy > m_matrix.m_BrdBox.GetBottom() )
|
|
|
|
oy = m_matrix.m_BrdBox.GetBottom();
|
|
|
|
|
|
|
|
if( fy < m_matrix.m_BrdBox.GetY() )
|
|
|
|
fy = m_matrix.m_BrdBox.GetY();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( fy > m_matrix.m_BrdBox.GetBottom() )
|
|
|
|
fy = m_matrix.m_BrdBox.GetBottom();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( Module->GetLayer() == F_Cu )
|
|
|
|
layerMask.set( F_Cu );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( Module->GetLayer() == B_Cu )
|
|
|
|
layerMask.set( B_Cu );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
m_matrix.TraceFilledRectangle( ox, oy, fx, fy, layerMask,
|
|
|
|
CELL_IS_MODULE, AR_MATRIX::WRITE_OR_CELL );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
// Trace pads + clearance areas.
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : Module->Pads() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-10-12 17:40:03 +00:00
|
|
|
int margin = (m_matrix.m_GridRouting / 2) + pad->GetOwnClearance( pad->GetLayer() );
|
2018-08-24 10:54:45 +00:00
|
|
|
m_matrix.PlacePad( pad, CELL_IS_MODULE, margin, AR_MATRIX::WRITE_OR_CELL );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
// Trace clearance.
|
|
|
|
int margin = ( m_matrix.m_GridRouting * Module->GetPadCount() ) / AR_GAIN;
|
|
|
|
m_matrix.CreateKeepOutRectangle( ox, oy, fx, fy, margin, AR_KEEPOUT_MARGIN , layerMask );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
|
|
|
// Build the footprint courtyard
|
|
|
|
buildFpAreas( Module, margin );
|
|
|
|
|
|
|
|
// Substract the shape to free areas
|
|
|
|
m_topFreeArea.BooleanSubtract( m_fpAreaTop, SHAPE_POLY_SET::PM_FAST );
|
|
|
|
m_bottomFreeArea.BooleanSubtract( m_fpAreaBottom, SHAPE_POLY_SET::PM_FAST );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
/* Test if the rectangular area (ux, ux .. y0, y1):
|
|
|
|
* - is a free zone (except OCCUPED_By_MODULE returns)
|
|
|
|
* - is on the working surface of the board (otherwise returns OUT_OF_BOARD)
|
|
|
|
*
|
|
|
|
* Returns OUT_OF_BOARD, or OCCUPED_By_MODULE or FREE_CELL if OK
|
|
|
|
*/
|
|
|
|
int AR_AUTOPLACER::testRectangle( const EDA_RECT& aRect, int side )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
rect.Inflate( m_matrix.m_GridRouting / 2 );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
wxPoint start = rect.GetOrigin();
|
|
|
|
wxPoint end = rect.GetEnd();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
start -= m_matrix.m_BrdBox.GetOrigin();
|
|
|
|
end -= m_matrix.m_BrdBox.GetOrigin();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
int row_min = start.y / m_matrix.m_GridRouting;
|
|
|
|
int row_max = end.y / m_matrix.m_GridRouting;
|
|
|
|
int col_min = start.x / m_matrix.m_GridRouting;
|
|
|
|
int col_max = end.x / m_matrix.m_GridRouting;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( start.y > row_min * m_matrix.m_GridRouting )
|
|
|
|
row_min++;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( start.x > col_min * m_matrix.m_GridRouting )
|
|
|
|
col_min++;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( row_max >= ( m_matrix.m_Nrows - 1 ) )
|
|
|
|
row_max = m_matrix.m_Nrows - 1;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( col_max >= ( m_matrix.m_Ncols - 1 ) )
|
|
|
|
col_max = m_matrix.m_Ncols - 1;
|
++PCBNew
* Removed Pcb_Frame argument from BOARD() constructor, since it precludes
having a BOARD being edited by more than one editor, it was a bad design.
And this meant removing m_PcbFrame from BOARD.
* removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame
* Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp
* added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance
* a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed,
such as dialog_mask_clearance, dialog_drc, etc.
* Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it
with build_version.h's #define BOARD_FILE_VERSION, although there may be a
better place for this constant.
* Made the public functions in PARAM_CFG_ARRAY be type const.
void SaveParam(..) const and void ReadParam(..) const
* PARAM_CFG_BASE now has virtual destructor since we have various way of
destroying the derived class and boost::ptr_vector must be told about this.
* Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use
an automatic PARAM_CFG_ARRAY which is on the stack.\
* PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array,
since it has to access the current BOARD and the BOARD can change.
Remember BOARD_DESIGN_SETTINGS are now in the BOARD.
* Made the m_BoundingBox member private, this was a brutally hard task,
and indicative of the lack of commitment to accessors and object oriented
design on the part of KiCad developers. We must do better.
Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox().
* Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
for( int row = row_min; row <= row_max; row++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
for( int col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
|
|
|
unsigned int data = m_matrix.GetCell( row, col, side );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( ( data & CELL_IS_ZONE ) == 0 )
|
|
|
|
return AR_OUT_OF_BOARD;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( (data & CELL_IS_MODULE) )
|
|
|
|
return AR_OCCUIPED_BY_MODULE;
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
return AR_FREE_CELL;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
/* Calculates and returns the clearance area of the rectangular surface
|
|
|
|
* aRect):
|
|
|
|
* (Sum of cells in terms of distance)
|
|
|
|
*/
|
|
|
|
unsigned int AR_AUTOPLACER::calculateKeepOutArea( const EDA_RECT& aRect, int side )
|
|
|
|
{
|
|
|
|
wxPoint start = aRect.GetOrigin();
|
|
|
|
wxPoint end = aRect.GetEnd();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
start -= m_matrix.m_BrdBox.GetOrigin();
|
|
|
|
end -= m_matrix.m_BrdBox.GetOrigin();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
int row_min = start.y / m_matrix.m_GridRouting;
|
|
|
|
int row_max = end.y / m_matrix.m_GridRouting;
|
|
|
|
int col_min = start.x / m_matrix.m_GridRouting;
|
|
|
|
int col_max = end.x / m_matrix.m_GridRouting;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( start.y > row_min * m_matrix.m_GridRouting )
|
|
|
|
row_min++;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( start.x > col_min * m_matrix.m_GridRouting )
|
|
|
|
col_min++;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( row_max >= ( m_matrix.m_Nrows - 1 ) )
|
|
|
|
row_max = m_matrix.m_Nrows - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( col_max >= ( m_matrix.m_Ncols - 1 ) )
|
|
|
|
col_max = m_matrix.m_Ncols - 1;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
unsigned int keepOutCost = 0;
|
|
|
|
|
|
|
|
for( int row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
for( int col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
|
|
|
// m_matrix.GetDist returns the "cost" of the cell
|
|
|
|
// at position (row, col)
|
|
|
|
// in autoplace this is the cost of the cell, if it is
|
|
|
|
// inside aRect
|
|
|
|
keepOutCost += m_matrix.GetDist( row, col, side );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
return keepOutCost;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
/* Test if the footprint can be placed on the board.
|
2018-08-24 10:54:45 +00:00
|
|
|
* Returns the value TstRectangle().
|
|
|
|
* Module is known by its bounding box
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2020-11-13 15:15:52 +00:00
|
|
|
int AR_AUTOPLACER::testFootprintOnBoard( FOOTPRINT* aFootprint, bool TstOtherSide,
|
2020-11-13 02:57:11 +00:00
|
|
|
const wxPoint& aOffset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
int side = AR_SIDE_TOP;
|
|
|
|
int otherside = AR_SIDE_BOTTOM;
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( aFootprint->GetLayer() == B_Cu )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
|
|
|
side = AR_SIDE_BOTTOM; otherside = AR_SIDE_TOP;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
EDA_RECT fpBBox = aFootprint->GetFootprintRect();
|
2018-08-24 10:54:45 +00:00
|
|
|
fpBBox.Move( -aOffset );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
buildFpAreas( aFootprint, 0 );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
int diag = //testModuleByPolygon( aFootprint, side, aOffset );
|
2018-12-15 16:50:42 +00:00
|
|
|
testRectangle( fpBBox, side );
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( diag != AR_FREE_CELL )
|
|
|
|
return diag;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( TstOtherSide )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
diag = //testModuleByPolygon( aFootprint, otherside, aOffset );
|
2018-12-15 16:50:42 +00:00
|
|
|
testRectangle( fpBBox, otherside );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( diag != AR_FREE_CELL )
|
|
|
|
return diag;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
int marge = ( m_matrix.m_GridRouting * aFootprint->GetPadCount() ) / AR_GAIN;
|
2017-02-20 16:57:41 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
fpBBox.Inflate( marge );
|
|
|
|
return calculateKeepOutArea( fpBBox, side );
|
2013-11-25 11:29:16 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
int AR_AUTOPLACER::getOptimalFPPlacement( FOOTPRINT* aFootprint )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int error = 1;
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint lastPosOK;
|
2013-11-24 17:48:14 +00:00
|
|
|
double min_cost, curr_cost, Score;
|
2020-11-13 02:57:11 +00:00
|
|
|
bool testOtherSide;
|
2012-06-08 09:56:42 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
aFootprint->CalculateBoundingBox();
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
lastPosOK = m_matrix.m_BrdBox.GetOrigin();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint fpPos = aFootprint->GetPosition();
|
|
|
|
EDA_RECT fpBBox = aFootprint->GetFootprintRect();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Move fpBBox to have the footprint position at (0,0)
|
2020-11-13 02:57:11 +00:00
|
|
|
fpBBox.Move( -fpPos );
|
2013-11-24 17:48:14 +00:00
|
|
|
wxPoint fpBBoxOrg = fpBBox.GetOrigin();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// Calculate the limit of the footprint position, relative to the routing matrix area
|
2018-08-24 10:54:45 +00:00
|
|
|
wxPoint xylimit = m_matrix.m_BrdBox.GetEnd() - fpBBox.GetEnd();
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
wxPoint initialPos = m_matrix.m_BrdBox.GetOrigin() - fpBBoxOrg;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Stay on grid.
|
2018-08-24 10:54:45 +00:00
|
|
|
initialPos.x -= initialPos.x % m_matrix.m_GridRouting;
|
|
|
|
initialPos.y -= initialPos.y % m_matrix.m_GridRouting;
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
m_curPosition = initialPos;
|
2020-11-13 02:57:11 +00:00
|
|
|
wxPoint fpOffset = fpPos - m_curPosition;
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// Examine pads, and set testOtherSide to true if a footprint has at least 1 pad through.
|
|
|
|
testOtherSide = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( m_matrix.m_RoutingLayersCount > 1 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
LSET other( aFootprint->GetLayer() == B_Cu ? F_Cu : B_Cu );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
if( !( pad->GetLayerSet() & other ).any() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
testOtherSide = true;
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
fpBBox.SetOrigin( fpBBoxOrg + m_curPosition );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
min_cost = -1.0;
|
2020-02-14 00:56:41 +00:00
|
|
|
// m_frame->SetStatusText( wxT( "Score ??, pos ??" ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
for( ; m_curPosition.x < xylimit.x; m_curPosition.x += m_matrix.m_GridRouting )
|
|
|
|
{
|
|
|
|
m_curPosition.y = initialPos.y;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
for( ; m_curPosition.y < xylimit.y; m_curPosition.y += m_matrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
fpBBox.SetOrigin( fpBBoxOrg + m_curPosition );
|
2020-11-13 02:57:11 +00:00
|
|
|
fpOffset = fpPos - m_curPosition;
|
|
|
|
int keepOutCost = testFootprintOnBoard( aFootprint, testOtherSide, fpOffset );
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( keepOutCost >= 0 ) // i.e. if the footprint can be put here
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
error = 0;
|
2020-11-13 11:17:15 +00:00
|
|
|
// m_frame->build_ratsnest_footprint( aFootprint ); // fixme
|
2020-11-13 02:57:11 +00:00
|
|
|
curr_cost = computePlacementRatsnestCost( aFootprint, fpOffset );
|
2013-11-24 17:48:14 +00:00
|
|
|
Score = curr_cost + keepOutCost;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( (min_cost >= Score ) || (min_cost < 0 ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
lastPosOK = m_curPosition;
|
2013-11-24 17:48:14 +00:00
|
|
|
min_cost = Score;
|
2007-08-10 19:14:51 +00:00
|
|
|
wxString msg;
|
2020-02-14 00:56:41 +00:00
|
|
|
/* msg.Printf( wxT( "Score %g, pos %s, %s" ),
|
2013-11-24 17:48:14 +00:00
|
|
|
min_cost,
|
2013-11-25 06:10:24 +00:00
|
|
|
GetChars( ::CoordinateToString( LastPosOK.x ) ),
|
|
|
|
GetChars( ::CoordinateToString( LastPosOK.y ) ) );
|
2018-08-24 10:54:45 +00:00
|
|
|
m_frame->SetStatusText( msg );*/
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Regeneration of the modified variable.
|
2020-11-13 02:57:11 +00:00
|
|
|
m_curPosition = lastPosOK;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
m_minCost = min_cost;
|
2007-08-10 19:14:51 +00:00
|
|
|
return error;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const PAD* AR_AUTOPLACER::nearestPad( FOOTPRINT *aRefFP, PAD* aRefPad, const wxPoint& aOffset)
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
const PAD* nearest = nullptr;
|
|
|
|
int64_t nearestDist = INT64_MAX;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
if ( footprint == aRefFP )
|
2018-08-24 10:54:45 +00:00
|
|
|
continue;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
if( !m_matrix.m_BrdBox.Contains( footprint->GetPosition() ) )
|
2018-08-24 10:54:45 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad: footprint->Pads() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( pad->GetNetCode() != aRefPad->GetNetCode() || pad->GetNetCode() <= 0 )
|
2018-08-24 10:54:45 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
auto dist = (VECTOR2I( aRefPad->GetPosition() - aOffset ) - VECTOR2I( pad->GetPosition() ) ).EuclideanNorm();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if ( dist < nearestDist )
|
|
|
|
{
|
|
|
|
nearestDist = dist;
|
|
|
|
nearest = pad;
|
|
|
|
}
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
return nearest;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
double AR_AUTOPLACER::computePlacementRatsnestCost( FOOTPRINT *aFootprint, const wxPoint& aOffset )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
double curr_cost;
|
2018-08-24 10:54:45 +00:00
|
|
|
VECTOR2I start; // start point of a ratsnest
|
|
|
|
VECTOR2I end; // end point of a ratsnest
|
2013-11-24 17:48:14 +00:00
|
|
|
int dx, dy;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
curr_cost = 0;
|
2010-01-29 20:36:12 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( PAD* pad : aFootprint->Pads() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
const PAD* nearest = nearestPad( aFootprint, pad, aOffset );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( !nearest )
|
|
|
|
continue;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
start = VECTOR2I( pad->GetPosition() ) - VECTOR2I(aOffset);
|
|
|
|
end = VECTOR2I( nearest->GetPosition() );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
//m_overlay->SetIsStroke( true );
|
|
|
|
//m_overlay->SetStrokeColor( COLOR4D(0.0, 1.0, 0.0, 1.0) );
|
|
|
|
//m_overlay->Line( start, end );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Cost of the ratsnest.
|
2013-11-24 17:48:14 +00:00
|
|
|
dx = end.x - start.x;
|
|
|
|
dy = end.y - start.y;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
dx = abs( dx );
|
|
|
|
dy = abs( dy );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// ttry to have always dx >= dy to calculate the cost of the rastsnet
|
|
|
|
if( dx < dy )
|
2015-06-26 13:41:56 +00:00
|
|
|
std::swap( dx, dy );
|
2012-06-08 09:56:42 +00:00
|
|
|
|
2016-07-11 03:09:18 +00:00
|
|
|
// Cost of the connection = length + penalty due to the slope
|
|
|
|
// dx is the biggest length relative to the X or Y axis
|
2012-06-08 09:56:42 +00:00
|
|
|
// the penalty is max for 45 degrees ratsnests,
|
|
|
|
// and 0 for horizontal or vertical ratsnests.
|
|
|
|
// For Horizontal and Vertical ratsnests, dy = 0;
|
2013-11-24 17:48:14 +00:00
|
|
|
double conn_cost = hypot( dx, dy * 2.0 );
|
|
|
|
curr_cost += conn_cost; // Total cost = sum of costs of each connection
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
return curr_cost;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Sort routines
|
2020-11-13 15:15:52 +00:00
|
|
|
static bool sortFootprintsByComplexity( FOOTPRINT* ref, FOOTPRINT* compare )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
double ff1, ff2;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
ff1 = ref->GetArea() * ref->GetPadCount();
|
|
|
|
ff2 = compare->GetArea() * compare->GetPadCount();
|
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
return ff2 < ff1;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
static bool sortFootprintsByRatsnestSize( FOOTPRINT* ref, FOOTPRINT* compare )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
double ff1, ff2;
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
ff1 = ref->GetArea() * ref->GetFlag();
|
|
|
|
ff2 = compare->GetArea() * compare->GetFlag();
|
2010-11-26 17:47:35 +00:00
|
|
|
return ff2 < ff1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* AR_AUTOPLACER::pickFootprint( )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<FOOTPRINT*> fpList;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->CalculateBoundingBox();
|
2020-11-13 01:12:36 +00:00
|
|
|
fpList.push_back( footprint );
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
sort( fpList.begin(), fpList.end(), sortFootprintsByComplexity );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
for( unsigned kk = 0; kk < fpList.size(); kk++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = fpList[kk];
|
2020-11-13 01:12:36 +00:00
|
|
|
footprint->SetFlag( 0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( !footprint->NeedsPlaced() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
m_connectivity->Update( footprint );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
m_connectivity->RecalculateRatsnest();
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
for( unsigned kk = 0; kk < fpList.size(); kk++ )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = fpList[kk];
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
auto edges = m_connectivity->GetRatsnestForComponent( footprint, true );
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
footprint->SetFlag( edges.size() ) ;
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
sort( fpList.begin(), fpList.end(), sortFootprintsByRatsnestSize );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Search for "best" footprint.
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* bestFootprint = nullptr;
|
|
|
|
FOOTPRINT* altFootprint = nullptr;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
for( unsigned ii = 0; ii < fpList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = fpList[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( !footprint->NeedsPlaced() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
altFootprint = footprint;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( footprint->GetFlag() == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
bestFootprint = footprint;
|
2010-11-26 17:47:35 +00:00
|
|
|
break;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
if( bestFootprint )
|
|
|
|
return bestFootprint;
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
2020-11-13 11:17:15 +00:00
|
|
|
return altFootprint;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
void AR_AUTOPLACER::drawPlacementRoutingMatrix( )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
// Draw the board free area
|
|
|
|
m_overlay->Clear();
|
|
|
|
m_overlay->SetIsFill( true );
|
|
|
|
m_overlay->SetIsStroke( false );
|
2010-11-26 17:47:35 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
SHAPE_POLY_SET freeArea = m_topFreeArea;
|
|
|
|
freeArea.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Draw the free polygon areas, top side:
|
|
|
|
if( freeArea.OutlineCount() > 0 )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2018-12-15 16:50:42 +00:00
|
|
|
m_overlay->SetIsFill( true );
|
|
|
|
m_overlay->SetIsStroke( false );
|
|
|
|
m_overlay->SetFillColor( COLOR4D(0.7, 0.0, 0.1, 0.2) );
|
|
|
|
m_overlay->Polygon( freeArea );
|
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
freeArea = m_bottomFreeArea;
|
|
|
|
freeArea.Fracture( SHAPE_POLY_SET::PM_FAST );
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
// Draw the free polygon areas, bottom side:
|
|
|
|
if( freeArea.OutlineCount() > 0 )
|
|
|
|
{
|
|
|
|
m_overlay->SetFillColor( COLOR4D(0.0, 0.7, 0.0, 0.2) );
|
|
|
|
m_overlay->Polygon( freeArea );
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2010-11-26 17:47:35 +00:00
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
AR_RESULT AR_AUTOPLACER::AutoplaceFootprints( std::vector<FOOTPRINT*>& aFootprints,
|
2020-11-13 01:12:36 +00:00
|
|
|
BOARD_COMMIT* aCommit,
|
|
|
|
bool aPlaceOffboardModules )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-08-31 11:54:07 +00:00
|
|
|
wxPoint memopos;
|
|
|
|
int error;
|
|
|
|
bool cancelled = false;
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
memopos = m_curPosition;
|
|
|
|
|
|
|
|
m_matrix.m_GridRouting = m_gridSize; //(int) m_frame->GetScreen()->GetGridSize().x;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
// Ensure Board.m_GridRouting has a reasonable value:
|
|
|
|
if( m_matrix.m_GridRouting < Millimeter2iu( 0.25 ) )
|
|
|
|
m_matrix.m_GridRouting = Millimeter2iu( 0.25 );
|
|
|
|
|
2020-11-13 11:17:15 +00:00
|
|
|
// Compute footprint parameters used in autoplace
|
2018-08-24 10:54:45 +00:00
|
|
|
if( genPlacementRoutingMatrix( ) == 0 )
|
|
|
|
return AR_FAILURE;
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
int placedCount = 0;
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->SetNeedsPlaced( false );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
std::vector<FOOTPRINT*> offboardMods;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( aPlaceOffboardModules )
|
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( !m_matrix.m_BrdBox.Contains( footprint->GetPosition() ) )
|
|
|
|
offboardMods.push_back( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : aFootprints )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->SetNeedsPlaced( true );
|
|
|
|
aCommit->Modify( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : offboardMods )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
footprint->SetNeedsPlaced( true );
|
|
|
|
aCommit->Modify( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : m_board->Footprints() )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint->NeedsPlaced() ) // Erase from screen
|
2020-11-13 02:57:11 +00:00
|
|
|
placedCount++;
|
2018-08-24 10:54:45 +00:00
|
|
|
else
|
2020-11-12 23:50:33 +00:00
|
|
|
genModuleOnRoutingMatrix( footprint );
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
wxString msg;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( m_progressReporter )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
m_progressReporter->Report( _( "Autoplacing components..." ) );
|
2020-11-13 02:57:11 +00:00
|
|
|
m_progressReporter->SetMaxProgress( placedCount );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 16:50:42 +00:00
|
|
|
drawPlacementRoutingMatrix();
|
|
|
|
|
|
|
|
if( m_refreshCallback )
|
|
|
|
m_refreshCallback( nullptr );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint;
|
2018-12-10 09:33:56 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
while( ( footprint = pickFootprint() ) != nullptr )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
// Display some info about activity, footprint placement can take a while:
|
2018-08-24 10:54:45 +00:00
|
|
|
//m_frame->SetStatusText( msg );
|
|
|
|
|
2018-12-10 09:33:56 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->SetTitle( wxString::Format(
|
2020-11-13 01:12:36 +00:00
|
|
|
_( "Autoplacing %s" ), footprint->GetReference() ) );
|
2018-12-10 09:33:56 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
double initialOrient = footprint->GetOrientation();
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
error = getOptimalFPPlacement( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
double bestScore = m_minCost;
|
|
|
|
double bestRotation = 0.0;
|
|
|
|
int rotAllowed;
|
|
|
|
|
|
|
|
if( error == AR_ABORT_PLACEMENT )
|
|
|
|
goto end_of_tst;
|
|
|
|
|
|
|
|
// Try orientations 90, 180, 270 degrees from initial orientation
|
2020-11-13 01:12:36 +00:00
|
|
|
rotAllowed = footprint->GetPlacementCost180();
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
if( rotAllowed != 0 )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, 1800.0, true );
|
|
|
|
error = getOptimalFPPlacement( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
m_minCost *= OrientationPenalty[rotAllowed];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( bestScore > m_minCost ) // This orientation is better.
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
bestScore = m_minCost;
|
|
|
|
bestRotation = 1800.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, initialOrient, false );
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( error == AR_ABORT_PLACEMENT )
|
|
|
|
goto end_of_tst;
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// Determine if the best orientation of a footprint is 90.
|
2020-11-13 01:12:36 +00:00
|
|
|
rotAllowed = footprint->GetPlacementCost90();
|
2018-12-10 09:33:56 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( rotAllowed != 0 )
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, 900.0, true );
|
|
|
|
error = getOptimalFPPlacement( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
m_minCost *= OrientationPenalty[rotAllowed];
|
2011-04-12 14:19:59 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( bestScore > m_minCost ) // This orientation is better.
|
|
|
|
{
|
|
|
|
bestScore = m_minCost;
|
|
|
|
bestRotation = 900.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, initialOrient, false );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( error == AR_ABORT_PLACEMENT )
|
|
|
|
goto end_of_tst;
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// Determine if the best orientation of a footprint is -90.
|
2018-08-24 10:54:45 +00:00
|
|
|
if( rotAllowed != 0 )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, 2700.0, true );
|
2020-11-13 02:57:11 +00:00
|
|
|
error = getOptimalFPPlacement( footprint );
|
2018-08-24 10:54:45 +00:00
|
|
|
m_minCost *= OrientationPenalty[rotAllowed];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( bestScore > m_minCost ) // This orientation is better.
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2018-08-24 10:54:45 +00:00
|
|
|
bestScore = m_minCost;
|
|
|
|
bestRotation = 2700.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, initialOrient, false );
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( error == AR_ABORT_PLACEMENT )
|
|
|
|
goto end_of_tst;
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
end_of_tst:
|
|
|
|
|
|
|
|
if( error == AR_ABORT_PLACEMENT )
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
bestRotation += initialOrient;
|
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
if( bestRotation != footprint->GetOrientation() )
|
2018-08-24 10:54:45 +00:00
|
|
|
{
|
2020-11-13 01:12:36 +00:00
|
|
|
rotateFootprint( footprint, bestRotation, false );
|
2018-08-24 10:54:45 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
// Place footprint.
|
2020-11-13 01:12:36 +00:00
|
|
|
placeFootprint( footprint, true, m_curPosition );
|
2018-08-24 10:54:45 +00:00
|
|
|
|
2020-11-13 01:12:36 +00:00
|
|
|
footprint->CalculateBoundingBox();
|
|
|
|
genModuleOnRoutingMatrix( footprint );
|
|
|
|
footprint->SetIsPlaced( true );
|
|
|
|
footprint->SetNeedsPlaced( false );
|
2018-12-15 16:50:42 +00:00
|
|
|
drawPlacementRoutingMatrix();
|
|
|
|
|
|
|
|
if( m_refreshCallback )
|
2020-11-13 01:12:36 +00:00
|
|
|
m_refreshCallback( footprint );
|
2018-12-15 16:50:42 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->AdvanceProgress();
|
2018-12-10 09:33:56 +00:00
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
if ( !m_progressReporter->KeepRefreshing( false ) )
|
|
|
|
{
|
|
|
|
cancelled = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cnt++;
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 10:54:45 +00:00
|
|
|
m_curPosition = memopos;
|
|
|
|
|
|
|
|
m_matrix.UnInitRoutingMatrix();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : m_board->Footprints() )
|
2020-11-13 02:57:11 +00:00
|
|
|
fp->CalculateBoundingBox();
|
2018-08-24 10:54:45 +00:00
|
|
|
|
|
|
|
return cancelled ? AR_CANCELLED : AR_COMPLETED;
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|