2011-09-20 13:57:40 +00:00
|
|
|
/**
|
|
|
|
* @file autorout.cpp
|
|
|
|
* @brief Autorouting command and control.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +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>
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <gr_basic.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <cell.h>
|
|
|
|
#include <zones.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
2012-06-05 19:07:33 +00:00
|
|
|
#include <convert_to_biu.h>
|
|
|
|
|
|
|
|
#include <autorout.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
MATRIX_ROUTING_HEAD RoutingMatrix; // routing matrix (grid) to route 2-sided boards
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* init board, route traces*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
int start, stop;
|
2007-10-13 06:18:44 +00:00
|
|
|
MODULE* Module = NULL;
|
|
|
|
D_PAD* Pad = NULL;
|
|
|
|
int autoroute_net_code = -1;
|
|
|
|
wxString msg;
|
|
|
|
|
2010-01-31 20:01:46 +00:00
|
|
|
if( GetBoard()->GetCopperLayerCount() > 1 )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2013-03-27 18:32:12 +00:00
|
|
|
g_Route_Layer_TOP = GetScreen()->m_Route_Layer_TOP;
|
|
|
|
g_Route_Layer_BOTTOM = GetScreen()->m_Route_Layer_BOTTOM;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-24 16:17:18 +00:00
|
|
|
g_Route_Layer_TOP = g_Route_Layer_BOTTOM = B_Cu;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( mode )
|
|
|
|
{
|
|
|
|
case ROUTE_NET:
|
|
|
|
if( GetScreen()->GetCurItem() )
|
|
|
|
{
|
|
|
|
switch( GetScreen()->GetCurItem()->Type() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_PAD_T:
|
2007-10-13 06:18:44 +00:00
|
|
|
Pad = (D_PAD*) GetScreen()->GetCurItem();
|
2014-02-25 10:40:34 +00:00
|
|
|
autoroute_net_code = Pad->GetNetCode();
|
2007-10-13 06:18:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( autoroute_net_code <= 0 )
|
|
|
|
{
|
2011-03-09 14:30:39 +00:00
|
|
|
wxMessageBox( _( "Net not selected" ) ); return;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ROUTE_MODULE:
|
|
|
|
Module = (MODULE*) GetScreen()->GetCurItem();
|
2011-10-01 19:24:27 +00:00
|
|
|
if( (Module == NULL) || (Module->Type() != PCB_MODULE_T) )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2014-11-02 12:44:57 +00:00
|
|
|
wxMessageBox( _( "Footprint not selected" ) );
|
2009-11-12 15:43:38 +00:00
|
|
|
return;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ROUTE_PAD:
|
|
|
|
Pad = (D_PAD*) GetScreen()->GetCurItem();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( (Pad == NULL) || (Pad->Type() != PCB_PAD_T) )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2011-03-09 14:30:39 +00:00
|
|
|
wxMessageBox( _( "Pad not selected" ) );
|
2009-11-12 15:43:38 +00:00
|
|
|
return;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
if( (GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
|
2011-03-09 14:30:39 +00:00
|
|
|
Compile_Ratsnest( DC, true );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Set the flag on the ratsnest to CH_ROUTE_REQ. */
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
RATSNEST_ITEM* ptmp = &GetBoard()->m_FullRatsnest[ii];
|
2009-05-24 18:28:36 +00:00
|
|
|
ptmp->m_Status &= ~CH_ROUTE_REQ;
|
2007-10-13 06:18:44 +00:00
|
|
|
|
|
|
|
switch( mode )
|
|
|
|
{
|
|
|
|
case ROUTE_ALL:
|
2009-11-12 15:43:38 +00:00
|
|
|
ptmp->m_Status |= CH_ROUTE_REQ;
|
|
|
|
break;
|
2007-10-13 06:18:44 +00:00
|
|
|
|
|
|
|
case ROUTE_NET:
|
|
|
|
if( autoroute_net_code == ptmp->GetNet() )
|
2009-05-24 18:28:36 +00:00
|
|
|
ptmp->m_Status |= CH_ROUTE_REQ;
|
2007-10-13 06:18:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ROUTE_MODULE:
|
|
|
|
{
|
2013-03-18 19:36:07 +00:00
|
|
|
D_PAD* pt_pad = (D_PAD*) Module->Pads();
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_pad != NULL; pt_pad = pt_pad->Next() )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
if( ptmp->m_PadStart == pt_pad )
|
|
|
|
ptmp->m_Status |= CH_ROUTE_REQ;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
if( ptmp->m_PadEnd == pt_pad )
|
|
|
|
ptmp->m_Status |= CH_ROUTE_REQ;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ROUTE_PAD:
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( ptmp->m_PadStart == Pad ) || ( ptmp->m_PadEnd == Pad ) )
|
2009-05-24 18:28:36 +00:00
|
|
|
ptmp->m_Status |= CH_ROUTE_REQ;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start = time( NULL );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Calculation of no fixed routing to 5 mils and more. */
|
2012-06-05 19:07:33 +00:00
|
|
|
RoutingMatrix.m_GridRouting = (int)GetScreen()->GetGridSize().x;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
if( RoutingMatrix.m_GridRouting < (5*IU_PER_MILS) )
|
|
|
|
RoutingMatrix.m_GridRouting = 5*IU_PER_MILS;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Calculated ncol and nrow, matrix size for routing. */
|
2012-06-05 19:07:33 +00:00
|
|
|
RoutingMatrix.ComputeMatrixSize( GetBoard() );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
m_messagePanel->EraseMsgBox();
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Map the board */
|
2012-06-26 17:57:37 +00:00
|
|
|
RoutingMatrix.m_RoutingLayersCount = 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
if( g_Route_Layer_TOP != g_Route_Layer_BOTTOM )
|
2012-06-26 17:57:37 +00:00
|
|
|
RoutingMatrix.m_RoutingLayersCount = 2;
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( RoutingMatrix.InitRoutingMatrix() < 0 )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2011-03-09 14:30:39 +00:00
|
|
|
wxMessageBox( _( "No memory for autorouting" ) );
|
2012-06-08 09:56:42 +00:00
|
|
|
RoutingMatrix.UnInitRoutingMatrix(); /* Free memory. */
|
2007-10-13 06:18:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( _( "Place Cells" ) );
|
2009-01-05 05:21:35 +00:00
|
|
|
PlaceCells( GetBoard(), -1, FORCE_PADS );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Construction of the track list for router. */
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.m_RouteCount = Build_Work( GetBoard() );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
// DisplayRoutingMatrix( m_canvas, DC );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2012-06-26 17:57:37 +00:00
|
|
|
Solve( DC, RoutingMatrix.m_RoutingLayersCount );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Free memory. */
|
|
|
|
FreeQueue();
|
|
|
|
InitWork(); /* Free memory for the list of router connections. */
|
2012-06-08 09:56:42 +00:00
|
|
|
RoutingMatrix.UnInitRoutingMatrix();
|
2007-10-13 06:18:44 +00:00
|
|
|
stop = time( NULL ) - start;
|
2011-02-11 20:48:13 +00:00
|
|
|
msg.Printf( wxT( "time = %d second%s" ), stop, ( stop == 1 ) ? wxT( "" ) : wxT( "s" ) );
|
|
|
|
SetStatusText( msg );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
/* Clear the flag CH_NOROUTABLE which is set to 1 by Solve(),
|
|
|
|
* when a track was not routed.
|
|
|
|
* (If this flag is 1 the corresponding track it is not rerouted)
|
2007-10-13 06:18:44 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::Reset_Noroutable( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK )== 0 )
|
2011-03-09 14:30:39 +00:00
|
|
|
Compile_Ratsnest( DC, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
GetBoard()->m_FullRatsnest[ii].m_Status &= ~CH_UNROUTABLE;
|
2007-10-13 06:18:44 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
/* DEBUG Function: displays the routing matrix */
|
2012-06-05 19:07:33 +00:00
|
|
|
void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-04-02 11:18:19 +00:00
|
|
|
int dcell0;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color;
|
2007-10-13 06:18:44 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
int maxi = 600 / RoutingMatrix.m_Ncols;
|
2009-11-12 15:43:38 +00:00
|
|
|
maxi = ( maxi * 3 ) / 4;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
if( !maxi )
|
|
|
|
maxi = 1;
|
|
|
|
|
2008-01-24 19:51:13 +00:00
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( int col = 0; col < RoutingMatrix.m_Ncols; col++ )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
for( int row = 0; row < RoutingMatrix.m_Nrows; row++ )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2012-09-02 12:06:47 +00:00
|
|
|
color = BLACK;
|
2012-06-10 16:21:18 +00:00
|
|
|
dcell0 = RoutingMatrix.GetCell( row, col, BOTTOM );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( dcell0 & HOLE )
|
2007-10-13 06:18:44 +00:00
|
|
|
color = GREEN;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2015-04-02 11:18:19 +00:00
|
|
|
#if 0
|
|
|
|
int dcell1 = 0;
|
|
|
|
|
|
|
|
if( RoutingMatrix.m_RoutingLayersCount )
|
|
|
|
dcell1 = GetCell( row, col, TOP );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
if( dcell1 & HOLE )
|
2012-09-02 12:06:47 +00:00
|
|
|
color = RED;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2015-04-02 11:18:19 +00:00
|
|
|
dcell0 |= dcell1;
|
|
|
|
#endif
|
2009-11-12 15:43:38 +00:00
|
|
|
if( !color && ( dcell0 & VIA_IMPOSSIBLE ) )
|
2007-10-13 06:18:44 +00:00
|
|
|
color = BLUE;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
if( dcell0 & CELL_is_EDGE )
|
2008-01-24 19:51:13 +00:00
|
|
|
color = YELLOW;
|
2008-11-24 06:53:43 +00:00
|
|
|
else if( dcell0 & CELL_is_ZONE )
|
2008-01-24 19:51:13 +00:00
|
|
|
color = YELLOW;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
#define DRAW_OFFSET_X -20
|
|
|
|
#define DRAW_OFFSET_Y 20
|
2008-01-24 19:51:13 +00:00
|
|
|
// if( color )
|
2007-10-13 06:18:44 +00:00
|
|
|
{
|
2012-06-05 19:07:33 +00:00
|
|
|
for( int i = 0; i < maxi; i++ )
|
|
|
|
for( int j = 0; j < maxi; j++ )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRPutPixel( panel->GetClipBox(), DC,
|
2011-01-30 22:22:38 +00:00
|
|
|
( col * maxi ) + i + DRAW_OFFSET_X,
|
|
|
|
( row * maxi ) + j + DRAW_OFFSET_Y, color );
|
2007-10-13 06:18:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|