KiCad PCB EDA Suite
AR_MATRIX Class Reference

AR_MATRIX handle the matrix routing that describes the actual board. More...

#include <ar_matrix.h>

Public Types

enum  CELL_OP {
  WRITE_CELL = 0, WRITE_OR_CELL = 1, WRITE_XOR_CELL = 2, WRITE_AND_CELL = 3,
  WRITE_ADD_CELL = 4
}
 
typedef unsigned char MATRIX_CELL
 
typedef int DIST_CELL
 
typedef char DIR_CELL
 

Public Member Functions

 AR_MATRIX ()
 
 ~AR_MATRIX ()
 
void WriteCell (int aRow, int aCol, int aSide, MATRIX_CELL aCell)
 
wxPoint GetBrdCoordOrigin ()
 function GetBrdCoordOrigin More...
 
bool ComputeMatrixSize (const EDA_RECT &aBoundingBox)
 Function ComputeMatrixSize calculates the number of rows and columns of dimensions of aPcb for routing and automatic calculation of area. More...
 
int InitRoutingMatrix ()
 Function InitBoard initializes the data structures. More...
 
void UnInitRoutingMatrix ()
 
void SetCellOperation (CELL_OP aLogicOp)
 
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)
 
int CalcDist (int x, int y, int z, int side)
 
int GetApxDist (int r1, int c1, int r2, int c2)
 
void TraceSegmentPcb (DRAWSEGMENT *pt_segm, int color, int marge, AR_MATRIX::CELL_OP op_logic)
 
void TraceSegmentPcb (TRACK *aTrack, int color, int marge, AR_MATRIX::CELL_OP op_logic)
 
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,y0 a x1,y1 are incremented by value aKeepOut Cell outside this rectangle, but inside the rectangle x0,y0 -marge to x1,y1 + marge are incremented by a decreasing value (aKeepOut ... More...
 
void PlacePad (D_PAD *aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic)
 
void TraceFilledRectangle (int ux0, int uy0, int ux1, int uy1, double angle, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
 
void TraceFilledRectangle (int ux0, int uy0, int ux1, int uy1, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
 

Public Attributes

MATRIX_CELLm_BoardSide [AR_MAX_ROUTING_LAYERS_COUNT]
 
DIST_CELLm_DistSide [AR_MAX_ROUTING_LAYERS_COUNT]
 
DIR_CELLm_DirSide [AR_MAX_ROUTING_LAYERS_COUNT]
 
bool m_InitMatrixDone
 
int m_RoutingLayersCount
 
int m_GridRouting
 
EDA_RECT m_BrdBox
 
int m_Nrows
 
int m_Ncols
 
int m_MemSize
 
int m_RouteCount
 
PCB_LAYER_ID m_routeLayerTop
 
PCB_LAYER_ID m_routeLayerBottom
 

Private Member Functions

void drawSegmentQcq (int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color, CELL_OP op_logic)
 
void traceCircle (int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, int color, AR_MATRIX::CELL_OP op_logic)
 
void traceFilledCircle (int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
 
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)
 
void tracePcbLine (int x0, int y0, int x1, int y1, LAYER_NUM layer, int color, AR_MATRIX::CELL_OP op_logic)
 

Private Attributes

void(AR_MATRIX::* m_opWriteCell )(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
 

Detailed Description

AR_MATRIX handle the matrix routing that describes the actual board.

Definition at line 49 of file ar_matrix.h.

Member Typedef Documentation

◆ DIR_CELL

typedef char AR_MATRIX::DIR_CELL

Definition at line 54 of file ar_matrix.h.

◆ DIST_CELL

typedef int AR_MATRIX::DIST_CELL

Definition at line 53 of file ar_matrix.h.

◆ MATRIX_CELL

typedef unsigned char AR_MATRIX::MATRIX_CELL

Definition at line 52 of file ar_matrix.h.

Member Enumeration Documentation

◆ CELL_OP

Enumerator
WRITE_CELL 
WRITE_OR_CELL 
WRITE_XOR_CELL 
WRITE_AND_CELL 
WRITE_ADD_CELL 

Definition at line 77 of file ar_matrix.h.

Constructor & Destructor Documentation

◆ AR_MATRIX()

AR_MATRIX::AR_MATRIX ( )

Definition at line 40 of file ar_matrix.cpp.

41 {
42  m_BoardSide[0] = nullptr;
43  m_BoardSide[1] = nullptr;
44  m_DistSide[0] = nullptr;
45  m_DistSide[1] = nullptr;
46  m_DirSide[0] = nullptr;
47  m_DirSide[1] = nullptr;
48  m_opWriteCell = nullptr;
49  m_InitMatrixDone = false;
50  m_Nrows = 0;
51  m_Ncols = 0;
52  m_MemSize = 0;
54  m_GridRouting = 0;
55  m_RouteCount = 0;
58 }
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
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
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
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
int m_RoutingLayersCount
Definition: ar_matrix.h:62
bool m_InitMatrixDone
Definition: ar_matrix.h:61
int m_RouteCount
Definition: ar_matrix.h:67
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70

References B_Cu, F_Cu, m_BoardSide, m_DirSide, m_DistSide, m_GridRouting, m_InitMatrixDone, m_MemSize, m_Ncols, m_Nrows, m_opWriteCell, m_RouteCount, m_routeLayerBottom, m_routeLayerTop, and m_RoutingLayersCount.

◆ ~AR_MATRIX()

AR_MATRIX::~AR_MATRIX ( )

Definition at line 61 of file ar_matrix.cpp.

62 {
63 }

Member Function Documentation

◆ AddCell()

void AR_MATRIX::AddCell ( int  aRow,
int  aCol,
int  aSide,
MATRIX_CELL  aCell 
)

Definition at line 255 of file ar_matrix.cpp.

256 {
257  MATRIX_CELL* p;
258 
259  p = m_BoardSide[aSide];
260  p[aRow * m_Ncols + aCol] += x;
261 }
int m_Ncols
Definition: ar_matrix.h:65
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52

References m_BoardSide, and m_Ncols.

Referenced by SetCellOperation().

◆ AndCell()

void AR_MATRIX::AndCell ( int  aRow,
int  aCol,
int  aSide,
MATRIX_CELL  aCell 
)

Definition at line 244 of file ar_matrix.cpp.

245 {
246  MATRIX_CELL* p;
247 
248  p = m_BoardSide[aSide];
249  p[aRow * m_Ncols + aCol] &= x;
250 }
int m_Ncols
Definition: ar_matrix.h:65
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52

References m_BoardSide, and m_Ncols.

Referenced by SetCellOperation().

◆ CalcDist()

int AR_MATRIX::CalcDist ( int  x,
int  y,
int  z,
int  side 
)

Definition at line 406 of file ar_matrix.cpp.

407 {
408  int adjust, ldist;
409 
410  adjust = 0; /* set if hole is encountered */
411 
412  if( x == CELL_IS_EMPTY )
413  x = 10;
414 
415  if( y == CELL_IS_EMPTY )
416  {
417  y = 10;
418  }
419  else if( y == FROM_OTHERSIDE )
420  {
421  if( z == CELL_IS_EMPTY )
422  z = 10;
423 
424  adjust = penalty[x - 1][z - 1];
425  }
426 
427  ldist = dist[x - 1][y - 1] + penalty[x - 1][y - 1] + adjust;
428 
429  if( m_RouteCount > 1 )
430  {
431  if( side == AR_SIDE_BOTTOM )
432  ldist += dir_penalty_TOP[x - 1][y - 1];
433 
434  if( side == AR_SIDE_TOP )
435  ldist += dir_penalty_BOTTOM[x - 1][y - 1];
436  }
437 
438  return ldist * 10;
439 }
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:43
static const int dist[10][10]
Definition: ar_matrix.cpp:326
#define AR_SIDE_TOP
Definition: ar_matrix.h:42
#define FROM_OTHERSIDE
Definition: ar_cell.h:108
static const int penalty[10][10]
Definition: ar_matrix.cpp:343
#define CELL_IS_EMPTY
Definition: ar_cell.h:35
static int dir_penalty_BOTTOM[10][10]
Definition: ar_matrix.cpp:378
static const int dir_penalty_TOP[10][10]
Definition: ar_matrix.cpp:361
int m_RouteCount
Definition: ar_matrix.h:67

References AR_SIDE_BOTTOM, AR_SIDE_TOP, CELL_IS_EMPTY, dir_penalty_BOTTOM, dir_penalty_TOP, dist, FROM_OTHERSIDE, m_RouteCount, and penalty.

◆ ComputeMatrixSize()

bool AR_MATRIX::ComputeMatrixSize ( const EDA_RECT aBoundingBox)

Function ComputeMatrixSize calculates the number of rows and columns of dimensions of aPcb for routing and automatic calculation of area.

Parameters
aPcb= the physical board
aUseBoardEdgesOnly= true to use board edges only, = false to use the full board bounding box (default)

Definition at line 68 of file ar_matrix.cpp.

69 {
70  // The boundary box must have its start point on routing grid:
71  m_BrdBox = aBoundingBox;
72 
75 
76  // The boundary box must have its end point on routing grid:
77  wxPoint end = m_BrdBox.GetEnd();
78 
79  end.x -= end.x % m_GridRouting;
80  end.x += m_GridRouting;
81 
82  end.y -= end.y % m_GridRouting;
83  end.y += m_GridRouting;
84 
85  m_BrdBox.SetEnd( end );
86 
89 
90  // gives a small margin
91  m_Ncols += 1;
92  m_Nrows += 1;
93 
94  return true;
95 }
int m_Ncols
Definition: ar_matrix.h:65
int GetX() const
Definition: eda_rect.h:111
int m_GridRouting
Definition: ar_matrix.h:63
EDA_RECT m_BrdBox
Definition: ar_matrix.h:64
int GetWidth() const
Definition: eda_rect.h:119
const wxPoint GetEnd() const
Definition: eda_rect.h:116
void SetEnd(int x, int y)
Definition: eda_rect.h:192
int m_Nrows
Definition: ar_matrix.h:65
void SetX(int val)
Definition: eda_rect.h:168
int GetHeight() const
Definition: eda_rect.h:120
void SetY(int val)
Definition: eda_rect.h:174
int GetY() const
Definition: eda_rect.h:112

References EDA_RECT::GetEnd(), EDA_RECT::GetHeight(), EDA_RECT::GetWidth(), EDA_RECT::GetX(), EDA_RECT::GetY(), m_BrdBox, m_GridRouting, m_Ncols, m_Nrows, EDA_RECT::SetEnd(), EDA_RECT::SetX(), EDA_RECT::SetY(), wxPoint::x, and wxPoint::y.

Referenced by AR_AUTOPLACER::genPlacementRoutingMatrix().

◆ CreateKeepOutRectangle()

void AR_MATRIX::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,y0 a x1,y1 are incremented by value aKeepOut Cell outside this rectangle, but inside the rectangle x0,y0 -marge to x1,y1 + marge are incremented by a decreasing value (aKeepOut ...

0). The decreasing value depends on the distance to the first rectangle Therefore the cost is high in rect x0,y0 to x1,y1, and decrease outside this rectangle

Definition at line 1181 of file ar_matrix.cpp.

1183 {
1184  int row, col;
1185  int row_min, row_max, col_min, col_max, pmarge;
1186  int trace = 0;
1187  DIST_CELL data, LocalKeepOut;
1188  int lgain, cgain;
1189 
1190  if( aLayerMask[m_routeLayerBottom] )
1191  trace = 1; // Trace on bottom layer.
1192 
1193  if( aLayerMask[m_routeLayerTop] && m_RoutingLayersCount )
1194  trace |= 2; // Trace on top layer.
1195 
1196  if( trace == 0 )
1197  return;
1198 
1199  ux0 -= m_BrdBox.GetX();
1200  uy0 -= m_BrdBox.GetY();
1201  ux1 -= m_BrdBox.GetX();
1202  uy1 -= m_BrdBox.GetY();
1203 
1204  ux0 -= marge;
1205  ux1 += marge;
1206  uy0 -= marge;
1207  uy1 += marge;
1208 
1209  pmarge = marge / m_GridRouting;
1210 
1211  if( pmarge < 1 )
1212  pmarge = 1;
1213 
1214  // Calculate the coordinate limits of the rectangle.
1215  row_max = uy1 / m_GridRouting;
1216  col_max = ux1 / m_GridRouting;
1217  row_min = uy0 / m_GridRouting;
1218 
1219  if( uy0 > row_min * m_GridRouting )
1220  row_min++;
1221 
1222  col_min = ux0 / m_GridRouting;
1223 
1224  if( ux0 > col_min * m_GridRouting )
1225  col_min++;
1226 
1227  if( row_min < 0 )
1228  row_min = 0;
1229 
1230  if( row_max >= ( m_Nrows - 1 ) )
1231  row_max = m_Nrows - 1;
1232 
1233  if( col_min < 0 )
1234  col_min = 0;
1235 
1236  if( col_max >= ( m_Ncols - 1 ) )
1237  col_max = m_Ncols - 1;
1238 
1239  for( row = row_min; row <= row_max; row++ )
1240  {
1241  lgain = 256;
1242 
1243  if( row < pmarge )
1244  lgain = ( 256 * row ) / pmarge;
1245  else if( row > row_max - pmarge )
1246  lgain = ( 256 * ( row_max - row ) ) / pmarge;
1247 
1248  for( col = col_min; col <= col_max; col++ )
1249  {
1250  // RoutingMatrix Dist map containt the "cost" of the cell
1251  // at position (row, col)
1252  // in autoplace this is the cost of the cell, when
1253  // a footprint overlaps it, near a "master" footprint
1254  // this cost is hight near the "master" footprint
1255  // and decrease with the distance
1256  cgain = 256;
1257  LocalKeepOut = aKeepOut;
1258 
1259  if( col < pmarge )
1260  cgain = ( 256 * col ) / pmarge;
1261  else if( col > col_max - pmarge )
1262  cgain = ( 256 * ( col_max - col ) ) / pmarge;
1263 
1264  cgain = ( cgain * lgain ) / 256;
1265 
1266  if( cgain != 256 )
1267  LocalKeepOut = ( LocalKeepOut * cgain ) / 256;
1268 
1269  if( trace & 1 )
1270  {
1271  data = GetDist( row, col, AR_SIDE_BOTTOM ) + LocalKeepOut;
1272  SetDist( row, col, AR_SIDE_BOTTOM, data );
1273  }
1274 
1275  if( trace & 2 )
1276  {
1277  data = GetDist( row, col, AR_SIDE_TOP );
1278  data = std::max( data, LocalKeepOut );
1279  SetDist( row, col, AR_SIDE_TOP, data );
1280  }
1281  }
1282  }
1283 }
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:43
#define AR_SIDE_TOP
Definition: ar_matrix.h:42
int m_Ncols
Definition: ar_matrix.h:65
int GetX() const
Definition: eda_rect.h:111
int m_GridRouting
Definition: ar_matrix.h:63
EDA_RECT m_BrdBox
Definition: ar_matrix.h:64
int DIST_CELL
Definition: ar_matrix.h:53
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
int m_Nrows
Definition: ar_matrix.h:65
int m_RoutingLayersCount
Definition: ar_matrix.h:62
int GetY() const
Definition: eda_rect.h:112
void SetDist(int aRow, int aCol, int aSide, DIST_CELL)
Definition: ar_matrix.cpp:275
DIST_CELL GetDist(int aRow, int aCol, int aSide)
Definition: ar_matrix.cpp:265
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70

References AR_SIDE_BOTTOM, AR_SIDE_TOP, GetDist(), EDA_RECT::GetX(), EDA_RECT::GetY(), m_BrdBox, m_GridRouting, m_Ncols, m_Nrows, m_routeLayerBottom, m_routeLayerTop, m_RoutingLayersCount, and SetDist().

Referenced by AR_AUTOPLACER::genModuleOnRoutingMatrix().

◆ drawSegmentQcq()

void AR_MATRIX::drawSegmentQcq ( int  ux0,
int  uy0,
int  ux1,
int  uy1,
int  lg,
LAYER_NUM  layer,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)
private

Definition at line 464 of file ar_matrix.cpp.

466 {
467  int64_t row, col;
468  int64_t inc;
469  int64_t row_max, col_max, row_min, col_min;
470  int64_t demi_pas;
471 
472  int cx, cy, dx, dy;
473 
474 
475  //printf("segmQcq %d %d %d %d\n", ux0, uy0, ux1, uy1);
476 
477  SetCellOperation( op_logic );
478 
479  // Make coordinate ux1 tj > ux0 to simplify calculations
480  if( ux1 < ux0 )
481  {
482  std::swap( ux1, ux0 );
483  std::swap( uy1, uy0 );
484  }
485 
486  // Calculating the incrementing the Y axis
487  inc = 1;
488 
489  if( uy1 < uy0 )
490  inc = -1;
491 
492  demi_pas = m_GridRouting / 2;
493 
494  col_min = ( ux0 - lg ) / m_GridRouting;
495 
496  if( col_min < 0 )
497  col_min = 0;
498 
499  col_max = ( ux1 + lg + demi_pas ) / m_GridRouting;
500 
501  if( col_max > ( m_Ncols - 1 ) )
502  col_max = m_Ncols - 1;
503 
504  if( inc > 0 )
505  {
506  row_min = ( uy0 - lg ) / m_GridRouting;
507  row_max = ( uy1 + lg + demi_pas ) / m_GridRouting;
508  }
509  else
510  {
511  row_min = ( uy1 - lg ) / m_GridRouting;
512  row_max = ( uy0 + lg + demi_pas ) / m_GridRouting;
513  }
514 
515  if( row_min < 0 )
516  row_min = 0;
517 
518  if( row_min > ( m_Nrows - 1 ) )
519  row_min = m_Nrows - 1;
520 
521  if( row_max < 0 )
522  row_max = 0;
523 
524  if( row_max > ( m_Nrows - 1 ) )
525  row_max = m_Nrows - 1;
526 
527  dx = ux1 - ux0;
528  dy = uy1 - uy0;
529 
530  double angle;
531  if( dx )
532  {
533  angle = ArcTangente( dy, dx );
534  }
535  else
536  {
537  angle = 900;
538 
539  if( dy < 0 )
540  angle = -900;
541  }
542 
543  RotatePoint( &dx, &dy, angle ); // dx = length, dy = 0
544 
545 
546  //printf("col_min %d max %d row_min %d max %d\n", col_min, col_max, row_min, row_max);
547 
548  for( col = col_min; col <= col_max; col++ )
549  {
550  int64_t cxr;
551  cxr = ( col * m_GridRouting ) - ux0;
552 
553  for( row = row_min; row <= row_max; row++ )
554  {
555  cy = ( row * m_GridRouting ) - uy0;
556  cx = cxr;
557  RotatePoint( &cx, &cy, angle );
558 
559  if( abs( cy ) > lg )
560  continue; // The point is too far on the Y axis.
561 
562  /* This point a test is close to the segment: the position
563  * along the X axis must be tested.
564  */
565  if( ( cx >= 0 ) && ( cx <= dx ) )
566  {
567  OP_CELL( layer, row, col );
568  continue;
569  }
570 
571  // Examination of extremities are rounded.
572  if( ( cx < 0 ) && ( cx >= -lg ) )
573  {
574  if( ( ( cx * cx ) + ( cy * cy ) ) <= ( lg * lg ) )
575  OP_CELL( layer, row, col );
576 
577  continue;
578  }
579 
580  if( ( cx > dx ) && ( cx <= ( dx + lg ) ) )
581  {
582  if( ( ( ( cx - dx ) * ( cx - dx ) ) + ( cy * cy ) ) <= ( lg * lg ) )
583  OP_CELL( layer, row, col );
584 
585  continue;
586  }
587  }
588  }
589 }
int m_Ncols
Definition: ar_matrix.h:65
int m_GridRouting
Definition: ar_matrix.h:63
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
int m_Nrows
Definition: ar_matrix.h:65
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:180
#define OP_CELL(layer, dy, dx)
Definition: ar_matrix.cpp:442
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:162

References PNS::angle(), ArcTangente(), m_GridRouting, m_Ncols, m_Nrows, OP_CELL, RotatePoint(), and SetCellOperation().

Referenced by traceArc(), traceCircle(), and TraceSegmentPcb().

◆ GetApxDist()

int AR_MATRIX::GetApxDist ( int  r1,
int  c1,
int  r2,
int  c2 
)

Definition at line 311 of file ar_matrix.cpp.

312 {
313  int d1, d2; /* row and column deltas */
314 
315  if( ( d1 = r1 - r2 ) < 0 ) /* get absolute row delta */
316  d1 = -d1;
317 
318  if( ( d2 = c1 - c2 ) < 0 ) /* get absolute column delta */
319  d2 = -d2;
320 
321  return ( d1 + d2 ) * 50;
322 }

◆ GetBrdCoordOrigin()

wxPoint AR_MATRIX::GetBrdCoordOrigin ( )
inline

function GetBrdCoordOrigin

Returns
the board coordinate corresponding to the routing matrix origin ( board coordinate offset )

Definition at line 99 of file ar_matrix.h.

100  {
101  return m_BrdBox.GetOrigin();
102  }
EDA_RECT m_BrdBox
Definition: ar_matrix.h:64
const wxPoint GetOrigin() const
Definition: eda_rect.h:114

References EDA_RECT::GetOrigin(), and m_BrdBox.

Referenced by AR_AUTOPLACER::fillMatrix(), traceFilledCircle(), TraceFilledRectangle(), and TraceSegmentPcb().

◆ GetCell()

AR_MATRIX::MATRIX_CELL AR_MATRIX::GetCell ( int  aRow,
int  aCol,
int  aSide 
)

Definition at line 200 of file ar_matrix.cpp.

201 {
202  MATRIX_CELL* p;
203 
204  p = m_BoardSide[aSide];
205  return p[aRow * m_Ncols + aCol];
206 }
int m_Ncols
Definition: ar_matrix.h:65
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52

References m_BoardSide, and m_Ncols.

Referenced by AR_AUTOPLACER::testRectangle().

◆ GetDir()

int AR_MATRIX::GetDir ( int  aRow,
int  aCol,
int  aSide 
)

Definition at line 285 of file ar_matrix.cpp.

286 {
287  DIR_CELL* p;
288 
289  p = m_DirSide[aSide];
290  return (int) ( p[aRow * m_Ncols + aCol] );
291 }
char DIR_CELL
Definition: ar_matrix.h:54
int m_Ncols
Definition: ar_matrix.h:65
DIR_CELL * m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:59

References m_DirSide, and m_Ncols.

◆ GetDist()

AR_MATRIX::DIST_CELL AR_MATRIX::GetDist ( int  aRow,
int  aCol,
int  aSide 
)

Definition at line 265 of file ar_matrix.cpp.

266 {
267  DIST_CELL* p;
268 
269  p = m_DistSide[aSide];
270  return p[aRow * m_Ncols + aCol];
271 }
DIST_CELL * m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:57
int m_Ncols
Definition: ar_matrix.h:65
int DIST_CELL
Definition: ar_matrix.h:53

References m_DistSide, and m_Ncols.

Referenced by AR_AUTOPLACER::calculateKeepOutArea(), and CreateKeepOutRectangle().

◆ InitRoutingMatrix()

int AR_MATRIX::InitRoutingMatrix ( )

Function InitBoard initializes the data structures.

Returns
the amount of memory used or -1 if default.

Definition at line 98 of file ar_matrix.cpp.

99 {
100  if( m_Nrows <= 0 || m_Ncols <= 0 )
101  return 0;
102 
103  m_InitMatrixDone = true; // we have been called
104 
105  // give a small margin for memory allocation:
106  int ii = ( m_Nrows + 1 ) * ( m_Ncols + 1 );
107 
108  int side = AR_SIDE_BOTTOM;
109  for( int jj = 0; jj < m_RoutingLayersCount; jj++ ) // m_RoutingLayersCount = 1 or 2
110  {
111  m_BoardSide[side] = nullptr;
112  m_DistSide[side] = nullptr;
113  m_DirSide[side] = nullptr;
114 
115  // allocate matrix & initialize everything to empty
116  m_BoardSide[side] = (MATRIX_CELL*) operator new( ii * sizeof( MATRIX_CELL ) );
117  memset( m_BoardSide[side], 0, ii * sizeof( MATRIX_CELL ) );
118 
119  if( m_BoardSide[side] == nullptr )
120  return -1;
121 
122  // allocate Distances
123  m_DistSide[side] = (DIST_CELL*) operator new( ii * sizeof( DIST_CELL ) );
124  memset( m_DistSide[side], 0, ii * sizeof( DIST_CELL ) );
125 
126  if( m_DistSide[side] == nullptr )
127  return -1;
128 
129  // allocate Dir (chars)
130  m_DirSide[side] = (char*) operator new( ii );
131  memset( m_DirSide[side], 0, ii );
132 
133  if( m_DirSide[side] == nullptr )
134  return -1;
135 
136  side = AR_SIDE_TOP;
137  }
138 
139  m_MemSize =
140  m_RouteCount * ii * ( sizeof( MATRIX_CELL ) + sizeof( DIST_CELL ) + sizeof( char ) );
141 
142  return m_MemSize;
143 }
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:43
DIST_CELL * m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:57
int m_MemSize
Definition: ar_matrix.h:66
#define AR_SIDE_TOP
Definition: ar_matrix.h:42
int m_Ncols
Definition: ar_matrix.h:65
int DIST_CELL
Definition: ar_matrix.h:53
int m_Nrows
Definition: ar_matrix.h:65
DIR_CELL * m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:59
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
int m_RoutingLayersCount
Definition: ar_matrix.h:62
bool m_InitMatrixDone
Definition: ar_matrix.h:61
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52
int m_RouteCount
Definition: ar_matrix.h:67

References AR_SIDE_BOTTOM, AR_SIDE_TOP, m_BoardSide, m_DirSide, m_DistSide, m_InitMatrixDone, m_MemSize, m_Ncols, m_Nrows, m_RouteCount, and m_RoutingLayersCount.

Referenced by AR_AUTOPLACER::genPlacementRoutingMatrix().

◆ OrCell()

void AR_MATRIX::OrCell ( int  aRow,
int  aCol,
int  aSide,
MATRIX_CELL  aCell 
)

Definition at line 222 of file ar_matrix.cpp.

223 {
224  MATRIX_CELL* p;
225 
226  p = m_BoardSide[aSide];
227  p[aRow * m_Ncols + aCol] |= x;
228 }
int m_Ncols
Definition: ar_matrix.h:65
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52

References m_BoardSide, and m_Ncols.

Referenced by SetCellOperation().

◆ PlacePad()

void AR_MATRIX::PlacePad ( D_PAD aPad,
int  color,
int  marge,
AR_MATRIX::CELL_OP  op_logic 
)

Definition at line 1286 of file ar_matrix.cpp.

1287 {
1288  int dx, dy;
1289  wxPoint shape_pos = aPad->ShapePos();
1290 
1291  dx = aPad->GetSize().x / 2;
1292  dx += marge;
1293 
1294  if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
1295  {
1296  traceFilledCircle( shape_pos.x, shape_pos.y, dx, aPad->GetLayerSet(), color, op_logic );
1297  return;
1298  }
1299 
1300  dy = aPad->GetSize().y / 2;
1301  dy += marge;
1302 
1303  if( aPad->GetShape() == PAD_SHAPE_TRAPEZOID )
1304  {
1305  dx += abs( aPad->GetDelta().y ) / 2;
1306  dy += abs( aPad->GetDelta().x ) / 2;
1307  }
1308 
1309  // The pad is a rectangle ( horizontal or vertical )
1310  if( int( aPad->GetOrientation() ) % 900 == 0 )
1311  {
1312  // Orientation turned 90 deg.
1313  if( aPad->GetOrientation() == 900 || aPad->GetOrientation() == 2700 )
1314  {
1315  std::swap( dx, dy );
1316  }
1317 
1318  TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy, shape_pos.x + dx,
1319  shape_pos.y + dy, aPad->GetLayerSet(), color, op_logic );
1320  }
1321  else
1322  {
1323  TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy, shape_pos.x + dx,
1324  shape_pos.y + dy, aPad->GetOrientation(), aPad->GetLayerSet(), color, op_logic );
1325  }
1326 }
int color
Definition: DXF_plotter.cpp:61
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:800
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:435
const wxSize & GetDelta() const
Definition: class_pad.h:288
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:411
wxPoint ShapePos() const
Definition: class_pad.cpp:601
void traceFilledCircle(int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:635
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:222
const wxSize & GetSize() const
Definition: class_pad.h:285

References color, D_PAD::GetDelta(), D_PAD::GetLayerSet(), D_PAD::GetOrientation(), D_PAD::GetShape(), D_PAD::GetSize(), PAD_SHAPE_CIRCLE, PAD_SHAPE_TRAPEZOID, D_PAD::ShapePos(), traceFilledCircle(), TraceFilledRectangle(), wxPoint::x, and wxPoint::y.

Referenced by AR_AUTOPLACER::genModuleOnRoutingMatrix().

◆ SetCell()

void AR_MATRIX::SetCell ( int  aRow,
int  aCol,
int  aSide,
MATRIX_CELL  aCell 
)

Definition at line 211 of file ar_matrix.cpp.

212 {
213  MATRIX_CELL* p;
214 
215  p = m_BoardSide[aSide];
216  p[aRow * m_Ncols + aCol] = x;
217 }
int m_Ncols
Definition: ar_matrix.h:65
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52

References m_BoardSide, and m_Ncols.

Referenced by AR_AUTOPLACER::fillMatrix(), and SetCellOperation().

◆ SetCellOperation()

void AR_MATRIX::SetCellOperation ( AR_MATRIX::CELL_OP  aLogicOp)

Definition at line 180 of file ar_matrix.cpp.

181 {
182  switch( aLogicOp )
183  {
184  default:
186 
188 
190 
192 
194  }
195 }
void XorCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:233
void OrCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:222
void(AR_MATRIX::* m_opWriteCell)(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:74
void SetCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:211
void AndCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:244
void AddCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:255

References AddCell(), AndCell(), m_opWriteCell, OrCell(), SetCell(), WRITE_ADD_CELL, WRITE_AND_CELL, WRITE_CELL, WRITE_OR_CELL, WRITE_XOR_CELL, and XorCell().

Referenced by drawSegmentQcq(), traceFilledCircle(), TraceFilledRectangle(), and tracePcbLine().

◆ SetDir()

void AR_MATRIX::SetDir ( int  aRow,
int  aCol,
int  aSide,
int  aDir 
)

Definition at line 295 of file ar_matrix.cpp.

296 {
297  DIR_CELL* p;
298 
299  p = m_DirSide[aSide];
300  p[aRow * m_Ncols + aCol] = (char) x;
301 }
char DIR_CELL
Definition: ar_matrix.h:54
int m_Ncols
Definition: ar_matrix.h:65
DIR_CELL * m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:59

References m_DirSide, and m_Ncols.

◆ SetDist()

void AR_MATRIX::SetDist ( int  aRow,
int  aCol,
int  aSide,
DIST_CELL  x 
)

Definition at line 275 of file ar_matrix.cpp.

276 {
277  DIST_CELL* p;
278 
279  p = m_DistSide[aSide];
280  p[aRow * m_Ncols + aCol] = x;
281 }
DIST_CELL * m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:57
int m_Ncols
Definition: ar_matrix.h:65
int DIST_CELL
Definition: ar_matrix.h:53

References m_DistSide, and m_Ncols.

Referenced by CreateKeepOutRectangle().

◆ traceArc()

void AR_MATRIX::traceArc ( int  ux0,
int  uy0,
int  ux1,
int  uy1,
double  ArcAngle,
int  lg,
LAYER_NUM  layer,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)
private

Definition at line 756 of file ar_matrix.cpp.

758 {
759  int radius, nb_segm;
760  int x0, y0, // Starting point of the current segment trace
761  x1, y1; // End point
762  int ii;
763  double angle, StAngle;
764 
765 
766  radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
767 
768  x0 = ux1 - ux0;
769  y0 = uy1 - uy0;
770  StAngle = ArcTangente( uy1 - uy0, ux1 - ux0 );
771 
772  if( lg < 1 )
773  lg = 1;
774 
775  nb_segm = ( 2 * radius ) / lg;
776  nb_segm = ( nb_segm * std::abs( ArcAngle ) ) / 3600;
777 
778  if( nb_segm < 5 )
779  nb_segm = 5;
780 
781  if( nb_segm > 100 )
782  nb_segm = 100;
783 
784  for( ii = 1; ii <= nb_segm; ii++ )
785  {
786  angle = ( ArcAngle * ii ) / nb_segm;
787  angle += StAngle;
788 
790 
791  x1 = KiROUND( cosdecideg( radius, angle ) );
792  y1 = KiROUND( cosdecideg( radius, angle ) );
793  drawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
794  x0 = x1;
795  y0 = y1;
796  }
797 }
int color
Definition: DXF_plotter.cpp:61
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:257
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:464
double cosdecideg(double r, double a)
Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:408
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:162

References PNS::angle(), ArcTangente(), color, cosdecideg(), drawSegmentQcq(), KiROUND(), and NORMALIZE_ANGLE_POS().

Referenced by TraceSegmentPcb().

◆ traceCircle()

void AR_MATRIX::traceCircle ( int  ux0,
int  uy0,
int  ux1,
int  uy1,
int  lg,
LAYER_NUM  layer,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)
private

Definition at line 596 of file ar_matrix.cpp.

598 {
599  int radius, nb_segm;
600  int x0, y0, // Starting point of the current segment trace.
601  x1, y1; // End point.
602  int ii;
603  int angle;
604 
605  radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
606 
607  x0 = x1 = radius;
608  y0 = y1 = 0;
609 
610  if( lg < 1 )
611  lg = 1;
612 
613  nb_segm = ( 2 * radius ) / lg;
614 
615  if( nb_segm < 5 )
616  nb_segm = 5;
617 
618  if( nb_segm > 100 )
619  nb_segm = 100;
620 
621  for( ii = 1; ii < nb_segm; ii++ )
622  {
623  angle = ( 3600 * ii ) / nb_segm;
624  x1 = KiROUND( cosdecideg( radius, angle ) );
625  y1 = KiROUND( sindecideg( radius, angle ) );
626  drawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
627  x0 = x1;
628  y0 = y1;
629  }
630 
631  drawSegmentQcq( x1 + ux0, y1 + uy0, ux0 + radius, uy0, lg, layer, color, op_logic );
632 }
int color
Definition: DXF_plotter.cpp:61
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:464
double cosdecideg(double r, double a)
Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:408
double sindecideg(double r, double a)
Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:399
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61

References PNS::angle(), color, cosdecideg(), drawSegmentQcq(), KiROUND(), and sindecideg().

Referenced by TraceSegmentPcb().

◆ traceFilledCircle()

void AR_MATRIX::traceFilledCircle ( int  cx,
int  cy,
int  radius,
LSET  aLayerMask,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)
private

Definition at line 635 of file ar_matrix.cpp.

637 {
638  int row, col;
639  int ux0, uy0, ux1, uy1;
640  int row_max, col_max, row_min, col_min;
641  int trace = 0;
642  double fdistmin, fdistx, fdisty;
643  int tstwrite = 0;
644  int distmin;
645 
646  if( aLayerMask[m_routeLayerBottom] )
647  trace = 1; // Trace on BOTTOM
648 
649  if( aLayerMask[m_routeLayerTop] )
650  if( m_RoutingLayersCount > 1 )
651  trace |= 2; // Trace on TOP
652 
653  if( trace == 0 )
654  return;
655 
656  SetCellOperation( op_logic );
657 
658  cx -= GetBrdCoordOrigin().x;
659  cy -= GetBrdCoordOrigin().y;
660 
661  distmin = radius;
662 
663  // Calculate the bounding rectangle of the circle.
664  ux0 = cx - radius;
665  uy0 = cy - radius;
666  ux1 = cx + radius;
667  uy1 = cy + radius;
668 
669  // Calculate limit coordinates of cells belonging to the rectangle.
670  row_max = uy1 / m_GridRouting;
671  col_max = ux1 / m_GridRouting;
672  row_min = uy0 / m_GridRouting; // if (uy0 > row_min*Board.m_GridRouting) row_min++;
673  col_min = ux0 / m_GridRouting; // if (ux0 > col_min*Board.m_GridRouting) col_min++;
674 
675  if( row_min < 0 )
676  row_min = 0;
677 
678  if( row_max >= ( m_Nrows - 1 ) )
679  row_max = m_Nrows - 1;
680 
681  if( col_min < 0 )
682  col_min = 0;
683 
684  if( col_max >= ( m_Ncols - 1 ) )
685  col_max = m_Ncols - 1;
686 
687  // Calculate coordinate limits of cell belonging to the rectangle.
688  if( row_min > row_max )
689  row_max = row_min;
690 
691  if( col_min > col_max )
692  col_max = col_min;
693 
694  fdistmin = (double) distmin * distmin;
695 
696  for( row = row_min; row <= row_max; row++ )
697  {
698  fdisty = (double) ( cy - ( row * m_GridRouting ) );
699  fdisty *= fdisty;
700 
701  for( col = col_min; col <= col_max; col++ )
702  {
703  fdistx = (double) ( cx - ( col * m_GridRouting ) );
704  fdistx *= fdistx;
705 
706  if( fdistmin <= ( fdistx + fdisty ) )
707  continue;
708 
709  if( trace & 1 )
710  WriteCell( row, col, AR_SIDE_BOTTOM, color );
711 
712  if( trace & 2 )
713  WriteCell( row, col, AR_SIDE_TOP, color );
714 
715  tstwrite = 1;
716  }
717  }
718 
719  if( tstwrite )
720  return;
721 
722  /* If no cell has been written, it affects the 4 neighboring diagonal
723  * (Adverse event: pad off grid in the center of the 4 neighboring
724  * diagonal) */
725  distmin = m_GridRouting / 2 + 1;
726  fdistmin = ( (double) distmin * distmin ) * 2; // Distance to center point diagonally
727 
728  for( row = row_min; row <= row_max; row++ )
729  {
730  fdisty = (double) ( cy - ( row * m_GridRouting ) );
731  fdisty *= fdisty;
732 
733  for( col = col_min; col <= col_max; col++ )
734  {
735  fdistx = (double) ( cx - ( col * m_GridRouting ) );
736  fdistx *= fdistx;
737 
738  if( fdistmin <= ( fdistx + fdisty ) )
739  continue;
740 
741  if( trace & 1 )
742  WriteCell( row, col, AR_SIDE_BOTTOM, color );
743 
744  if( trace & 2 )
745  WriteCell( row, col, AR_SIDE_TOP, color );
746  }
747  }
748 }
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:43
#define AR_SIDE_TOP
Definition: ar_matrix.h:42
int m_Ncols
Definition: ar_matrix.h:65
int m_GridRouting
Definition: ar_matrix.h:63
int color
Definition: DXF_plotter.cpp:61
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
void WriteCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:89
int m_Nrows
Definition: ar_matrix.h:65
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:180
int m_RoutingLayersCount
Definition: ar_matrix.h:62
wxPoint GetBrdCoordOrigin()
function GetBrdCoordOrigin
Definition: ar_matrix.h:99
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70

References AR_SIDE_BOTTOM, AR_SIDE_TOP, color, GetBrdCoordOrigin(), m_GridRouting, m_Ncols, m_Nrows, m_routeLayerBottom, m_routeLayerTop, m_RoutingLayersCount, SetCellOperation(), WriteCell(), wxPoint::x, and wxPoint::y.

Referenced by PlacePad(), and TraceSegmentPcb().

◆ TraceFilledRectangle() [1/2]

void AR_MATRIX::TraceFilledRectangle ( int  ux0,
int  uy0,
int  ux1,
int  uy1,
double  angle,
LSET  aLayerMask,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)

Definition at line 800 of file ar_matrix.cpp.

802 {
803  int row, col;
804  int cx, cy; // Center of rectangle
805  int radius; // Radius of the circle
806  int row_min, row_max, col_min, col_max;
807  int rotrow, rotcol;
808  int trace = 0;
809 
810  if( aLayerMask[m_routeLayerBottom] )
811  trace = 1; // Trace on BOTTOM
812 
813  if( aLayerMask[m_routeLayerTop] )
814  {
815  if( m_RoutingLayersCount > 1 )
816  trace |= 2; // Trace on TOP
817  }
818 
819  if( trace == 0 )
820  return;
821 
822  SetCellOperation( op_logic );
823 
824  ux0 -= GetBrdCoordOrigin().x;
825  uy0 -= GetBrdCoordOrigin().y;
826  ux1 -= GetBrdCoordOrigin().x;
827  uy1 -= GetBrdCoordOrigin().y;
828 
829  cx = ( ux0 + ux1 ) / 2;
830  cy = ( uy0 + uy1 ) / 2;
831  radius = KiROUND( Distance( ux0, uy0, cx, cy ) );
832 
833  // Calculating coordinate limits belonging to the rectangle.
834  row_max = ( cy + radius ) / m_GridRouting;
835  col_max = ( cx + radius ) / m_GridRouting;
836  row_min = ( cy - radius ) / m_GridRouting;
837 
838  if( uy0 > row_min * m_GridRouting )
839  row_min++;
840 
841  col_min = ( cx - radius ) / m_GridRouting;
842 
843  if( ux0 > col_min * m_GridRouting )
844  col_min++;
845 
846  if( row_min < 0 )
847  row_min = 0;
848 
849  if( row_max >= ( m_Nrows - 1 ) )
850  row_max = m_Nrows - 1;
851 
852  if( col_min < 0 )
853  col_min = 0;
854 
855  if( col_max >= ( m_Ncols - 1 ) )
856  col_max = m_Ncols - 1;
857 
858  for( row = row_min; row <= row_max; row++ )
859  {
860  for( col = col_min; col <= col_max; col++ )
861  {
862  rotrow = row * m_GridRouting;
863  rotcol = col * m_GridRouting;
864  RotatePoint( &rotcol, &rotrow, cx, cy, -angle );
865 
866  if( rotrow <= uy0 )
867  continue;
868 
869  if( rotrow >= uy1 )
870  continue;
871 
872  if( rotcol <= ux0 )
873  continue;
874 
875  if( rotcol >= ux1 )
876  continue;
877 
878  if( trace & 1 )
879  WriteCell( row, col, AR_SIDE_BOTTOM, color );
880 
881  if( trace & 2 )
882  WriteCell( row, col, AR_SIDE_TOP, color );
883  }
884  }
885 }
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:43
#define AR_SIDE_TOP
Definition: ar_matrix.h:42
int m_Ncols
Definition: ar_matrix.h:65
int m_GridRouting
Definition: ar_matrix.h:63
int color
Definition: DXF_plotter.cpp:61
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
void WriteCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:89
int m_Nrows
Definition: ar_matrix.h:65
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:180
int m_RoutingLayersCount
Definition: ar_matrix.h:62
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
wxPoint GetBrdCoordOrigin()
function GetBrdCoordOrigin
Definition: ar_matrix.h:99
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70

References PNS::angle(), AR_SIDE_BOTTOM, AR_SIDE_TOP, color, GetBrdCoordOrigin(), KiROUND(), m_GridRouting, m_Ncols, m_Nrows, m_routeLayerBottom, m_routeLayerTop, m_RoutingLayersCount, RotatePoint(), SetCellOperation(), WriteCell(), wxPoint::x, and wxPoint::y.

Referenced by AR_AUTOPLACER::genModuleOnRoutingMatrix(), and PlacePad().

◆ TraceFilledRectangle() [2/2]

void AR_MATRIX::TraceFilledRectangle ( int  ux0,
int  uy0,
int  ux1,
int  uy1,
LSET  aLayerMask,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)

Definition at line 888 of file ar_matrix.cpp.

890 {
891  int row, col;
892  int row_min, row_max, col_min, col_max;
893  int trace = 0;
894 
895  if( aLayerMask[m_routeLayerBottom] )
896  trace = 1; // Trace on BOTTOM
897 
898  if( aLayerMask[m_routeLayerTop] && m_RoutingLayersCount > 1 )
899  trace |= 2; // Trace on TOP
900 
901  if( trace == 0 )
902  return;
903 
904  SetCellOperation( op_logic );
905 
906  ux0 -= GetBrdCoordOrigin().x;
907  uy0 -= GetBrdCoordOrigin().y;
908  ux1 -= GetBrdCoordOrigin().x;
909  uy1 -= GetBrdCoordOrigin().y;
910 
911  // Calculating limits coord cells belonging to the rectangle.
912  row_max = uy1 / m_GridRouting;
913  col_max = ux1 / m_GridRouting;
914  row_min = uy0 / m_GridRouting;
915 
916  if( uy0 > row_min * m_GridRouting )
917  row_min++;
918 
919  col_min = ux0 / m_GridRouting;
920 
921  if( ux0 > col_min * m_GridRouting )
922  col_min++;
923 
924  if( row_min < 0 )
925  row_min = 0;
926 
927  if( row_max >= ( m_Nrows - 1 ) )
928  row_max = m_Nrows - 1;
929 
930  if( col_min < 0 )
931  col_min = 0;
932 
933  if( col_max >= ( m_Ncols - 1 ) )
934  col_max = m_Ncols - 1;
935 
936  for( row = row_min; row <= row_max; row++ )
937  {
938  for( col = col_min; col <= col_max; col++ )
939  {
940  if( trace & 1 )
941  WriteCell( row, col, AR_SIDE_BOTTOM, color );
942 
943  if( trace & 2 )
944  WriteCell( row, col, AR_SIDE_TOP, color );
945  }
946  }
947 }
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:43
#define AR_SIDE_TOP
Definition: ar_matrix.h:42
int m_Ncols
Definition: ar_matrix.h:65
int m_GridRouting
Definition: ar_matrix.h:63
int color
Definition: DXF_plotter.cpp:61
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
void WriteCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:89
int m_Nrows
Definition: ar_matrix.h:65
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:180
int m_RoutingLayersCount
Definition: ar_matrix.h:62
wxPoint GetBrdCoordOrigin()
function GetBrdCoordOrigin
Definition: ar_matrix.h:99
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70

References AR_SIDE_BOTTOM, AR_SIDE_TOP, color, GetBrdCoordOrigin(), m_GridRouting, m_Ncols, m_Nrows, m_routeLayerBottom, m_routeLayerTop, m_RoutingLayersCount, SetCellOperation(), WriteCell(), wxPoint::x, and wxPoint::y.

◆ tracePcbLine()

void AR_MATRIX::tracePcbLine ( int  x0,
int  y0,
int  x1,
int  y1,
LAYER_NUM  layer,
int  color,
AR_MATRIX::CELL_OP  op_logic 
)
private

Definition at line 952 of file ar_matrix.cpp.

954 {
955  int dx, dy, lim;
956  int cumul, inc, il, delta;
957 
958  SetCellOperation( op_logic );
959 
960  if( x0 == x1 ) // Vertical.
961  {
962  if( y1 < y0 )
963  std::swap( y0, y1 );
964 
965  dy = y0 / m_GridRouting;
966  lim = y1 / m_GridRouting;
967  dx = x0 / m_GridRouting;
968 
969  // Clipping limits of board.
970  if( ( dx < 0 ) || ( dx >= m_Ncols ) )
971  return;
972 
973  if( dy < 0 )
974  dy = 0;
975 
976  if( lim >= m_Nrows )
977  lim = m_Nrows - 1;
978 
979  for( ; dy <= lim; dy++ )
980  {
981  OP_CELL( layer, dy, dx );
982  }
983 
984  return;
985  }
986 
987  if( y0 == y1 ) // Horizontal
988  {
989  if( x1 < x0 )
990  std::swap( x0, x1 );
991 
992  dx = x0 / m_GridRouting;
993  lim = x1 / m_GridRouting;
994  dy = y0 / m_GridRouting;
995 
996  // Clipping limits of board.
997  if( ( dy < 0 ) || ( dy >= m_Nrows ) )
998  return;
999 
1000  if( dx < 0 )
1001  dx = 0;
1002 
1003  if( lim >= m_Ncols )
1004  lim = m_Ncols - 1;
1005 
1006  for( ; dx <= lim; dx++ )
1007  {
1008  OP_CELL( layer, dy, dx );
1009  }
1010 
1011  return;
1012  }
1013 
1014  // Here is some perspective: using the algorithm LUCAS.
1015  if( abs( x1 - x0 ) >= abs( y1 - y0 ) ) // segment slightly inclined/
1016  {
1017  if( x1 < x0 )
1018  {
1019  std::swap( x1, x0 );
1020  std::swap( y1, y0 );
1021  }
1022 
1023  dx = x0 / m_GridRouting;
1024  lim = x1 / m_GridRouting;
1025  dy = y0 / m_GridRouting;
1026  inc = 1;
1027 
1028  if( y1 < y0 )
1029  inc = -1;
1030 
1031  il = lim - dx;
1032  cumul = il / 2;
1033  delta = abs( y1 - y0 ) / m_GridRouting;
1034 
1035  for( ; dx <= lim; )
1036  {
1037  if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < m_Ncols ) && ( dy < m_Nrows ) )
1038  {
1039  OP_CELL( layer, dy, dx );
1040  }
1041 
1042  dx++;
1043  cumul += delta;
1044 
1045  if( cumul > il )
1046  {
1047  cumul -= il;
1048  dy += inc;
1049  }
1050  }
1051  }
1052  else
1053  {
1054  if( y1 < y0 )
1055  {
1056  std::swap( x1, x0 );
1057  std::swap( y1, y0 );
1058  }
1059 
1060  dy = y0 / m_GridRouting;
1061  lim = y1 / m_GridRouting;
1062  dx = x0 / m_GridRouting;
1063  inc = 1;
1064 
1065  if( x1 < x0 )
1066  inc = -1;
1067 
1068  il = lim - dy;
1069  cumul = il / 2;
1070  delta = abs( x1 - x0 ) / m_GridRouting;
1071 
1072  for( ; dy <= lim; )
1073  {
1074  if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < m_Ncols ) && ( dy < m_Nrows ) )
1075  {
1076  OP_CELL( layer, dy, dx );
1077  }
1078 
1079  dy++;
1080  cumul += delta;
1081 
1082  if( cumul > il )
1083  {
1084  cumul -= il;
1085  dx += inc;
1086  }
1087  }
1088  }
1089 }
int m_Ncols
Definition: ar_matrix.h:65
int m_GridRouting
Definition: ar_matrix.h:63
int m_Nrows
Definition: ar_matrix.h:65
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:180
#define OP_CELL(layer, dy, dx)
Definition: ar_matrix.cpp:442

References m_GridRouting, m_Ncols, m_Nrows, OP_CELL, and SetCellOperation().

◆ TraceSegmentPcb() [1/2]

void AR_MATRIX::TraceSegmentPcb ( DRAWSEGMENT pt_segm,
int  color,
int  marge,
AR_MATRIX::CELL_OP  op_logic 
)

Definition at line 1091 of file ar_matrix.cpp.

1093 {
1094  int half_width = ( pt_segm->GetWidth() / 2 ) + marge;
1095 
1096  // Calculate the bounding rectangle of the segment (if H, V or Via)
1097  int ux0 = pt_segm->GetStart().x - GetBrdCoordOrigin().x;
1098  int uy0 = pt_segm->GetStart().y - GetBrdCoordOrigin().y;
1099  int ux1 = pt_segm->GetEnd().x - GetBrdCoordOrigin().x;
1100  int uy1 = pt_segm->GetEnd().y - GetBrdCoordOrigin().y;
1101 
1102  //printf("traceSegm %d %d %d %d\n", ux0, uy0, ux1, uy1);
1103 
1104  LAYER_NUM layer = pt_segm->GetLayer();
1105 
1106  //if( color == VIA_IMPOSSIBLE )
1107  layer = UNDEFINED_LAYER;
1108 
1109 
1110  switch( pt_segm->GetShape() )
1111  {
1112  // The segment is here a straight line or a circle or an arc.:
1113  case S_CIRCLE: traceCircle( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic ); break;
1114 
1115  case S_ARC:
1116  traceArc( ux0, uy0, ux1, uy1, pt_segm->GetAngle(), half_width, layer, color, op_logic );
1117  break;
1118 
1119  // The segment is here a line segment.
1120  default: drawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic ); break;
1121  }
1122 }
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:756
STROKE_T GetShape() const
int color
Definition: DXF_plotter.cpp:61
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
Arcs (with rounded ends)
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:464
int GetWidth() const
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:596
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
double GetAngle() const
wxPoint GetBrdCoordOrigin()
function GetBrdCoordOrigin
Definition: ar_matrix.h:99
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.

References color, drawSegmentQcq(), DRAWSEGMENT::GetAngle(), GetBrdCoordOrigin(), DRAWSEGMENT::GetEnd(), BOARD_ITEM::GetLayer(), DRAWSEGMENT::GetShape(), DRAWSEGMENT::GetStart(), DRAWSEGMENT::GetWidth(), S_ARC, S_CIRCLE, traceArc(), traceCircle(), UNDEFINED_LAYER, wxPoint::x, and wxPoint::y.

Referenced by AR_AUTOPLACER::genPlacementRoutingMatrix().

◆ TraceSegmentPcb() [2/2]

void AR_MATRIX::TraceSegmentPcb ( TRACK aTrack,
int  color,
int  marge,
AR_MATRIX::CELL_OP  op_logic 
)

Definition at line 1125 of file ar_matrix.cpp.

1126 {
1127  int half_width = ( aTrack->GetWidth() / 2 ) + marge;
1128 
1129  // Test if VIA (filled circle need to be drawn)
1130  if( aTrack->Type() == PCB_VIA_T )
1131  {
1132  LSET layer_mask;
1133 
1134  if( aTrack->IsOnLayer( m_routeLayerBottom ) )
1135  layer_mask.set( m_routeLayerBottom );
1136 
1137  if( aTrack->IsOnLayer( m_routeLayerTop ) )
1138  {
1139  if( !layer_mask.any() )
1140  layer_mask = LSET( m_routeLayerTop );
1141  else
1142  layer_mask.set();
1143  }
1144 
1145  if( color == VIA_IMPOSSIBLE )
1146  layer_mask.set();
1147 
1148  if( layer_mask.any() )
1149  traceFilledCircle( aTrack->GetStart().x, aTrack->GetStart().y, half_width, layer_mask,
1150  color, op_logic );
1151  }
1152  else
1153  {
1154  // Calculate the bounding rectangle of the segment
1155  int ux0 = aTrack->GetStart().x - GetBrdCoordOrigin().x;
1156  int uy0 = aTrack->GetStart().y - GetBrdCoordOrigin().y;
1157  int ux1 = aTrack->GetEnd().x - GetBrdCoordOrigin().x;
1158  int uy1 = aTrack->GetEnd().y - GetBrdCoordOrigin().y;
1159 
1160  // Ordinary track
1161  PCB_LAYER_ID layer = aTrack->GetLayer();
1162 
1163  if( color == VIA_IMPOSSIBLE )
1164  layer = UNDEFINED_LAYER;
1165 
1166  drawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
1167  }
1168 }
const wxPoint & GetStart() const
Definition: class_track.h:118
int color
Definition: DXF_plotter.cpp:61
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:69
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
#define VIA_IMPOSSIBLE
Definition: ar_cell.h:44
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:464
int GetWidth() const
Definition: class_track.h:112
wxPoint GetBrdCoordOrigin()
function GetBrdCoordOrigin
Definition: ar_matrix.h:99
void traceFilledCircle(int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:635
const wxPoint & GetEnd() const
Definition: class_track.h:115
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:70

References color, drawSegmentQcq(), GetBrdCoordOrigin(), TRACK::GetEnd(), BOARD_ITEM::GetLayer(), TRACK::GetStart(), TRACK::GetWidth(), BOARD_ITEM::IsOnLayer(), m_routeLayerBottom, m_routeLayerTop, PCB_VIA_T, traceFilledCircle(), EDA_ITEM::Type(), UNDEFINED_LAYER, VIA_IMPOSSIBLE, wxPoint::x, and wxPoint::y.

◆ UnInitRoutingMatrix()

void AR_MATRIX::UnInitRoutingMatrix ( )

Definition at line 146 of file ar_matrix.cpp.

147 {
148  int ii;
149 
150  m_InitMatrixDone = false;
151 
152  for( ii = 0; ii < AR_MAX_ROUTING_LAYERS_COUNT; ii++ )
153  {
154  // de-allocate Dir matrix
155  if( m_DirSide[ii] )
156  {
157  delete m_DirSide[ii];
158  m_DirSide[ii] = nullptr;
159  }
160 
161  // de-allocate Distances matrix
162  if( m_DistSide[ii] )
163  {
164  delete m_DistSide[ii];
165  m_DistSide[ii] = nullptr;
166  }
167 
168  // de-allocate cells matrix
169  if( m_BoardSide[ii] )
170  {
171  delete m_BoardSide[ii];
172  m_BoardSide[ii] = nullptr;
173  }
174  }
175 
176  m_Nrows = m_Ncols = 0;
177 }
DIST_CELL * m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:57
int m_Ncols
Definition: ar_matrix.h:65
int m_Nrows
Definition: ar_matrix.h:65
DIR_CELL * m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:59
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
bool m_InitMatrixDone
Definition: ar_matrix.h:61
#define AR_MAX_ROUTING_LAYERS_COUNT
Definition: ar_matrix.h:40

References AR_MAX_ROUTING_LAYERS_COUNT, m_BoardSide, m_DirSide, m_DistSide, m_InitMatrixDone, m_Ncols, and m_Nrows.

Referenced by AR_AUTOPLACER::AutoplaceModules(), and AR_AUTOPLACER::genPlacementRoutingMatrix().

◆ WriteCell()

void AR_MATRIX::WriteCell ( int  aRow,
int  aCol,
int  aSide,
MATRIX_CELL  aCell 
)
inline

Definition at line 89 of file ar_matrix.h.

90  {
91  ( *this.*m_opWriteCell )( aRow, aCol, aSide, aCell );
92  }
void(AR_MATRIX::* m_opWriteCell)(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:74

References m_opWriteCell.

Referenced by traceFilledCircle(), and TraceFilledRectangle().

◆ XorCell()

void AR_MATRIX::XorCell ( int  aRow,
int  aCol,
int  aSide,
MATRIX_CELL  aCell 
)

Definition at line 233 of file ar_matrix.cpp.

234 {
235  MATRIX_CELL* p;
236 
237  p = m_BoardSide[aSide];
238  p[aRow * m_Ncols + aCol] ^= x;
239 }
int m_Ncols
Definition: ar_matrix.h:65
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:56
unsigned char MATRIX_CELL
Definition: ar_matrix.h:52

References m_BoardSide, and m_Ncols.

Referenced by SetCellOperation().

Member Data Documentation

◆ m_BoardSide

◆ m_BrdBox

◆ m_DirSide

DIR_CELL* AR_MATRIX::m_DirSide[AR_MAX_ROUTING_LAYERS_COUNT]

Definition at line 59 of file ar_matrix.h.

Referenced by AR_MATRIX(), GetDir(), InitRoutingMatrix(), SetDir(), and UnInitRoutingMatrix().

◆ m_DistSide

DIST_CELL* AR_MATRIX::m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]

Definition at line 57 of file ar_matrix.h.

Referenced by AR_MATRIX(), GetDist(), InitRoutingMatrix(), SetDist(), and UnInitRoutingMatrix().

◆ m_GridRouting

◆ m_InitMatrixDone

bool AR_MATRIX::m_InitMatrixDone

Definition at line 61 of file ar_matrix.h.

Referenced by AR_MATRIX(), InitRoutingMatrix(), and UnInitRoutingMatrix().

◆ m_MemSize

int AR_MATRIX::m_MemSize

Definition at line 66 of file ar_matrix.h.

Referenced by AR_MATRIX(), and InitRoutingMatrix().

◆ m_Ncols

◆ m_Nrows

◆ m_opWriteCell

void( AR_MATRIX::* AR_MATRIX::m_opWriteCell) (int aRow, int aCol, int aSide, MATRIX_CELL aCell)
private

Definition at line 74 of file ar_matrix.h.

Referenced by AR_MATRIX(), SetCellOperation(), and WriteCell().

◆ m_RouteCount

int AR_MATRIX::m_RouteCount

Definition at line 67 of file ar_matrix.h.

Referenced by AR_MATRIX(), CalcDist(), and InitRoutingMatrix().

◆ m_routeLayerBottom

◆ m_routeLayerTop

◆ m_RoutingLayersCount


The documentation for this class was generated from the following files: