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) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2012 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
|
|
|
|
*/
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
/**
|
|
|
|
* @file autorout.h
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#ifndef AUTOROUT_H
|
|
|
|
#define AUTOROUT_H
|
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <base_struct.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
class BOARD;
|
|
|
|
|
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
#define TOP 0
|
2007-06-05 12:10:51 +00:00
|
|
|
#define BOTTOM 1
|
2007-10-13 06:18:44 +00:00
|
|
|
#define EMPTY 0
|
2007-06-05 12:10:51 +00:00
|
|
|
#define ILLEGAL -1
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Autorouter commands. */
|
2012-06-26 17:57:37 +00:00
|
|
|
enum AUTOPLACEROUTE_OPTIONS
|
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
PLACE_ALL,
|
|
|
|
PLACE_OUT_OF_BOARD,
|
|
|
|
PLACE_INCREMENTAL,
|
|
|
|
PLACE_1_MODULE,
|
|
|
|
|
|
|
|
ROUTE_ALL,
|
|
|
|
ROUTE_NET,
|
|
|
|
ROUTE_MODULE,
|
|
|
|
ROUTE_PAD
|
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-06-26 17:57:37 +00:00
|
|
|
#define MAX_ROUTING_LAYERS_COUNT 2
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
#define FORCE_PADS 1 /* Force placement of pads for any Netcode */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* search statistics */
|
2009-04-05 20:49:15 +00:00
|
|
|
extern int OpenNodes; /* total number of nodes opened */
|
|
|
|
extern int ClosNodes; /* total number of nodes closed */
|
|
|
|
extern int MoveNodes; /* total number of nodes moved */
|
|
|
|
extern int MaxNodes; /* maximum number of nodes opened at one time */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Structures useful to the generation of board as bitmap. */
|
2011-03-09 14:30:39 +00:00
|
|
|
typedef char MATRIX_CELL;
|
|
|
|
typedef int DIST_CELL;
|
2011-09-20 13:57:40 +00:00
|
|
|
typedef char DIR_CELL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* class MATRIX_ROUTING_HEAD
|
2012-06-10 16:21:18 +00:00
|
|
|
* handle the matrix routing that describes the actual board
|
2011-11-10 15:55:05 +00:00
|
|
|
*/
|
2012-06-10 16:21:18 +00:00
|
|
|
class MATRIX_ROUTING_HEAD
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-06-26 17:57:37 +00:00
|
|
|
MATRIX_CELL* m_BoardSide[MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides
|
|
|
|
DIST_CELL* m_DistSide[MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides:
|
|
|
|
// distance to cells
|
|
|
|
DIR_CELL* m_DirSide[MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides:
|
|
|
|
// pointers back to source
|
2012-06-08 09:56:42 +00:00
|
|
|
bool m_InitMatrixDone;
|
2012-06-26 17:57:37 +00:00
|
|
|
int m_RoutingLayersCount; // Number of layers for autorouting (0 or 1)
|
2011-09-20 13:57:40 +00:00
|
|
|
int m_GridRouting; // Size of grid for autoplace/autoroute
|
|
|
|
EDA_RECT m_BrdBox; // Actual board bounding box
|
2012-06-10 16:21:18 +00:00
|
|
|
int m_Nrows, m_Ncols; // Matrix size
|
|
|
|
int m_MemSize; // Memory requirement, just for statistics
|
|
|
|
int m_RouteCount; // Number of routes
|
2012-06-26 17:57:37 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
private:
|
2012-06-26 17:57:37 +00:00
|
|
|
// a pointer to the current selected cell operation
|
|
|
|
void (MATRIX_ROUTING_HEAD::* m_opWriteCell)( int aRow, int aCol,
|
|
|
|
int aSide, MATRIX_CELL aCell);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2011-03-09 14:30:39 +00:00
|
|
|
MATRIX_ROUTING_HEAD();
|
|
|
|
~MATRIX_ROUTING_HEAD();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
void WriteCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell)
|
|
|
|
{
|
|
|
|
(*this.*m_opWriteCell)( aRow, aCol, aSide, aCell );
|
|
|
|
}
|
|
|
|
|
2012-06-17 16:06:12 +00:00
|
|
|
/**
|
|
|
|
* function GetBrdCoordOrigin
|
2012-06-26 17:57:37 +00:00
|
|
|
* @return the board coordinate corresponding to the
|
2012-06-17 16:06:12 +00:00
|
|
|
* routing matrix origin ( board coordinate offset )
|
|
|
|
*/
|
|
|
|
wxPoint GetBrdCoordOrigin()
|
|
|
|
{
|
|
|
|
return m_BrdBox.GetOrigin();
|
|
|
|
}
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* Function ComputeMatrixSize
|
|
|
|
* calculates the number of rows and columns of dimensions of \a aPcb for routing and
|
|
|
|
* automatic calculation of area.
|
2012-06-08 09:56:42 +00:00
|
|
|
* @param aPcb = the physical board
|
|
|
|
* @param aUseBoardEdgesOnly = true to use board edges only,
|
|
|
|
* = false to use the full board bounding box (default)
|
2011-11-10 15:55:05 +00:00
|
|
|
*/
|
2012-06-08 09:56:42 +00:00
|
|
|
bool ComputeMatrixSize( BOARD* aPcb, bool aUseBoardEdgesOnly = false );
|
2011-11-10 15:55:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function InitBoard
|
|
|
|
* initializes the data structures.
|
|
|
|
*
|
|
|
|
* @return the amount of memory used or -1 if default.
|
|
|
|
*/
|
2012-06-08 09:56:42 +00:00
|
|
|
int InitRoutingMatrix();
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
void UnInitRoutingMatrix();
|
2012-06-10 16:21:18 +00:00
|
|
|
|
|
|
|
// Initialize WriteCell to make the aLogicOp
|
|
|
|
void SetCellOperation( int aLogicOp );
|
|
|
|
|
|
|
|
// functions to read/write one cell ( point on grid routing matrix:
|
|
|
|
MATRIX_CELL GetCell( int aRow, int aCol, int aSide);
|
|
|
|
void SetCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
|
|
|
|
void OrCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
|
|
|
|
void XorCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
|
|
|
|
void AndCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
|
|
|
|
void AddCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
|
|
|
|
DIST_CELL GetDist( int aRow, int aCol, int aSide );
|
|
|
|
void SetDist( int aRow, int aCol, int aSide, DIST_CELL );
|
|
|
|
int GetDir( int aRow, int aCol, int aSide );
|
|
|
|
void SetDir( int aRow, int aCol, int aSide, int aDir);
|
2012-06-26 17:57:37 +00:00
|
|
|
|
|
|
|
// calculate distance (with penalty) of a trace through a cell
|
|
|
|
int CalcDist(int x,int y,int z ,int side );
|
|
|
|
|
|
|
|
// calculate approximate distance (manhattan distance)
|
|
|
|
int GetApxDist( int r1, int c1, int r2, int c2 );
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
extern MATRIX_ROUTING_HEAD RoutingMatrix; /* 2-sided board */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Constants used to trace the cells on the BOARD */
|
2007-10-13 06:18:44 +00:00
|
|
|
#define WRITE_CELL 0
|
|
|
|
#define WRITE_OR_CELL 1
|
2007-06-05 12:10:51 +00:00
|
|
|
#define WRITE_XOR_CELL 2
|
|
|
|
#define WRITE_AND_CELL 3
|
|
|
|
#define WRITE_ADD_CELL 4
|
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
// Functions:
|
|
|
|
|
|
|
|
class PCB_EDIT_FRAME;
|
|
|
|
class BOARD;
|
|
|
|
class D_PAD;
|
|
|
|
class RATSNEST_ITEM;
|
|
|
|
class TRACK;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize a color value, the cells included in the board edge of the
|
|
|
|
* pad surface by pt_pad, with the margin reserved for isolation and the
|
|
|
|
* half width of the runway
|
|
|
|
* Parameters:
|
|
|
|
* Pt_pad: pointer to the description of the pad
|
|
|
|
* color: mask write in cells
|
|
|
|
* margin: add a value to the radius or half the score pad
|
|
|
|
* op_logic: type of writing in the cell (WRITE, OR)
|
|
|
|
*/
|
2012-06-17 16:06:12 +00:00
|
|
|
void PlacePad( D_PAD* pt_pad, int type, int marge, int op_logic );
|
2012-06-05 19:07:33 +00:00
|
|
|
|
|
|
|
/* Draws a segment of track on the board. */
|
2012-06-17 16:06:12 +00:00
|
|
|
void TraceSegmentPcb( TRACK* pt_segm, int type, int marge, int op_logic );
|
2012-06-05 19:07:33 +00:00
|
|
|
|
|
|
|
/* Uses the color value of all cells included in the board
|
|
|
|
* coord of the rectangle ux0, uy0 (top right corner)
|
|
|
|
* a ux1, uy1 (lower left corner) (coord PCB)
|
|
|
|
* the rectangle is horizontal (or vertical)
|
|
|
|
* masque_layer = mask layers;
|
|
|
|
* op_logic = WRITE_CELL, WRITE_OR_CELL, WRITE_XOR_CELL, WRITE_AND_CELL
|
|
|
|
*/
|
2012-06-17 16:06:12 +00:00
|
|
|
void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
|
2012-06-05 19:07:33 +00:00
|
|
|
int side, int color, int op_logic);
|
|
|
|
|
|
|
|
|
|
|
|
/* Same as above, but the rectangle is inclined angle angle. */
|
2012-06-17 16:06:12 +00:00
|
|
|
void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
|
2012-06-05 19:07:33 +00:00
|
|
|
int angle, int masque_layer, int color, int op_logic );
|
|
|
|
|
|
|
|
/* QUEUE.CPP */
|
|
|
|
void FreeQueue();
|
|
|
|
void InitQueue();
|
|
|
|
void GetQueue( int *, int *, int *, int *, int * );
|
|
|
|
int SetQueue( int, int, int, int, int, int, int );
|
|
|
|
void ReSetQueue( int, int, int, int, int, int, int );
|
|
|
|
|
|
|
|
/* WORK.CPP */
|
|
|
|
void InitWork();
|
|
|
|
void ReInitWork();
|
|
|
|
int SetWork( int, int, int , int, int, RATSNEST_ITEM *, int );
|
|
|
|
void GetWork( int *, int *, int *, int *, int *, RATSNEST_ITEM ** );
|
|
|
|
void SortWork(); /* order the work items; shortest first */
|
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
/* routing_matrix.cpp */
|
2012-06-05 19:07:33 +00:00
|
|
|
int Build_Work( BOARD * Pcb );
|
|
|
|
void PlaceCells( BOARD * Pcb, int net_code, int flag = 0 );
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-12-01 03:42:52 +00:00
|
|
|
#endif // AUTOROUT_H
|