KiCad PCB EDA Suite
ar_matrix.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-2015 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_MATRIX_H
30 #define __AR_MATRIX_H
31 
32 #include <eda_rect.h>
34 
35 class DRAWSEGMENT;
36 class TRACK;
37 class D_PAD;
38 class MODULE;
39 
40 #define AR_MAX_ROUTING_LAYERS_COUNT 2
41 
42 #define AR_SIDE_TOP 0
43 #define AR_SIDE_BOTTOM 1
44 
49 class AR_MATRIX
50 {
51 public:
52  typedef unsigned char MATRIX_CELL;
53  typedef int DIST_CELL;
54  typedef char DIR_CELL;
55 
56  MATRIX_CELL* m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides
57  DIST_CELL* m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides:
58  // distance to cells
59  DIR_CELL* m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]; // the image map of 2 board sides:
60  // pointers back to source
62  int m_RoutingLayersCount; // Number of layers for autorouting (0 or 1)
63  int m_GridRouting; // Size of grid for autoplace/autoroute
64  EDA_RECT m_BrdBox; // Actual board bounding box
65  int m_Nrows, m_Ncols; // Matrix size
66  int m_MemSize; // Memory requirement, just for statistics
67  int m_RouteCount; // Number of routes
68 
71 
72 private:
73  // a pointer to the current selected cell operation
74  void ( AR_MATRIX::*m_opWriteCell )( int aRow, int aCol, int aSide, MATRIX_CELL aCell );
75 
76 public:
77  enum CELL_OP
78  {
84  };
85 
86  AR_MATRIX();
87  ~AR_MATRIX();
88 
89  void WriteCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell )
90  {
91  ( *this.*m_opWriteCell )( aRow, aCol, aSide, aCell );
92  }
93 
100  {
101  return m_BrdBox.GetOrigin();
102  }
103 
112  bool ComputeMatrixSize( const EDA_RECT& aBoundingBox );
113 
120  int InitRoutingMatrix();
121 
122  void UnInitRoutingMatrix();
123 
124  // Initialize WriteCell to make the aLogicOp
125  void SetCellOperation( CELL_OP aLogicOp );
126 
127  // functions to read/write one cell ( point on grid routing matrix:
128  MATRIX_CELL GetCell( int aRow, int aCol, int aSide );
129  void SetCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell );
130  void OrCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell );
131  void XorCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell );
132  void AndCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell );
133  void AddCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell );
134  DIST_CELL GetDist( int aRow, int aCol, int aSide );
135  void SetDist( int aRow, int aCol, int aSide, DIST_CELL );
136  int GetDir( int aRow, int aCol, int aSide );
137  void SetDir( int aRow, int aCol, int aSide, int aDir );
138 
139  // calculate distance (with penalty) of a trace through a cell
140  int CalcDist( int x, int y, int z, int side );
141 
142  // calculate approximate distance (manhattan distance)
143  int GetApxDist( int r1, int c1, int r2, int c2 );
144 
145 
146  void TraceSegmentPcb( DRAWSEGMENT* pt_segm, int color, int marge, AR_MATRIX::CELL_OP op_logic );
147  void TraceSegmentPcb( TRACK* aTrack, int color, int marge, AR_MATRIX::CELL_OP op_logic );
149  int ux0, int uy0, int ux1, int uy1, int marge, int aKeepOut, LSET aLayerMask );
150  void PlacePad( D_PAD* aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic );
151  void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double angle, LSET aLayerMask,
152  int color, AR_MATRIX::CELL_OP op_logic );
153  void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, LSET aLayerMask, int color,
154  AR_MATRIX::CELL_OP op_logic );
155 
156 private:
157 
158  void drawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color,
159  CELL_OP op_logic );
160 
161  void traceCircle( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color,
162  AR_MATRIX::CELL_OP op_logic );
163  void traceFilledCircle(
164  int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic );
165  void traceArc( int ux0, int uy0, int ux1, int uy1, double ArcAngle, int lg, LAYER_NUM layer,
166  int color, AR_MATRIX::CELL_OP op_logic );
167  void tracePcbLine( int x0, int y0, int x1, int y1, LAYER_NUM layer, int color,
168  AR_MATRIX::CELL_OP op_logic );
169 };
170 
171 #endif
int GetApxDist(int r1, int c1, int r2, int c2)
Definition: ar_matrix.cpp:305
void traceArc(int ux0, int uy0, int ux1, int uy1, double ArcAngle, int lg, LAYER_NUM layer, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:750
class AR_MATRIX handle the matrix routing that describes the actual board
Definition: ar_matrix.h:49
char DIR_CELL
Definition: ar_matrix.h:54
int InitRoutingMatrix()
Function InitBoard initializes the data structures.
Definition: ar_matrix.cpp:92
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
DIST_CELL * m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:57
int m_MemSize
Definition: ar_matrix.h:66
int m_Ncols
Definition: ar_matrix.h:65
int m_GridRouting
Definition: ar_matrix.h:63
void tracePcbLine(int x0, int y0, int x1, int y1, LAYER_NUM layer, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:946
int color
Definition: DXF_plotter.cpp:62
void TraceFilledRectangle(int ux0, int uy0, int ux1, int uy1, double angle, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:794
EDA_RECT m_BrdBox
Definition: ar_matrix.h:64
int CalcDist(int x, int y, int z, int side)
Definition: ar_matrix.cpp:400
void CreateKeepOutRectangle(int ux0, int uy0, int ux1, int uy1, int marge, int aKeepOut, LSET aLayerMask)
Function CreateKeepOutRectangle builds the cost map: Cells ( in Dist map ) inside the rect x0...
Definition: ar_matrix.cpp:1175
void PlacePad(D_PAD *aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:1280
void TraceSegmentPcb(DRAWSEGMENT *pt_segm, int color, int marge, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:1085
int DIST_CELL
Definition: ar_matrix.h:53
void XorCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:227
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
void WriteCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:89
void OrCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:216
MATRIX_CELL GetCell(int aRow, int aCol, int aSide)
Definition: ar_matrix.cpp:194
void(AR_MATRIX::* m_opWriteCell)(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:74
int m_Nrows
Definition: ar_matrix.h:65
DIR_CELL * m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:59
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:174
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
void SetCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:205
void drawSegmentQcq(int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color, CELL_OP op_logic)
Definition: ar_matrix.cpp:458
void AndCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:238
void traceCircle(int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:590
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void UnInitRoutingMatrix()
Definition: ar_matrix.cpp:140
Board layer functions and definitions.
int m_RoutingLayersCount
Definition: ar_matrix.h:62
bool m_InitMatrixDone
Definition: ar_matrix.h:61
int GetDir(int aRow, int aCol, int aSide)
Definition: ar_matrix.cpp:279
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
wxPoint GetBrdCoordOrigin()
function GetBrdCoordOrigin
Definition: ar_matrix.h:99
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void AddCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:249
void SetDir(int aRow, int aCol, int aSide, int aDir)
Definition: ar_matrix.cpp:289
void traceFilledCircle(int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:629
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52
void SetDist(int aRow, int aCol, int aSide, DIST_CELL)
Definition: ar_matrix.cpp:269
bool ComputeMatrixSize(const EDA_RECT &aBoundingBox)
Function ComputeMatrixSize calculates the number of rows and columns of dimensions of aPcb for routin...
Definition: ar_matrix.cpp:62
#define AR_MAX_ROUTING_LAYERS_COUNT
Definition: ar_matrix.h:40
int m_RouteCount
Definition: ar_matrix.h:67
DIST_CELL GetDist(int aRow, int aCol, int aSide)
Definition: ar_matrix.cpp:259
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70