KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ar_matrix.cpp
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, [email protected]
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
7 *
8 * Copyright (C) 1992-2022 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#include "ar_matrix.h"
29#include <math/util.h> // for KiROUND
30#include <math_for_graphics.h>
31#include <trigo.h>
32
33#include <pcb_shape.h>
34#include <pad.h>
35
36
38{
39 m_BoardSide[0] = nullptr;
40 m_BoardSide[1] = nullptr;
41 m_DistSide[0] = nullptr;
42 m_DistSide[1] = nullptr;
43 m_opWriteCell = nullptr;
44 m_Nrows = 0;
45 m_Ncols = 0;
46 m_MemSize = 0;
48 m_GridRouting = 0;
49 m_RouteCount = 0;
52}
53
54
56{
57}
58
59// was: bool AR_MATRIX::ComputeMatrixSize( BOARD* aPcb, bool aUseBoardEdgesOnly )
60// aUseBoardEdgesOnly ? aPcb->GetBoardEdgesBoundingBox() : aPcb->GetBoundingBox();
61
62bool AR_MATRIX::ComputeMatrixSize( const BOX2I& aBoundingBox )
63{
64 // The boundary box must have its start point on routing grid:
65 m_BrdBox = aBoundingBox;
66
69
70 // The boundary box must have its end point on routing grid:
71 VECTOR2I end = m_BrdBox.GetEnd();
72
73 end.x -= end.x % m_GridRouting;
74 end.x += m_GridRouting;
75
76 end.y -= end.y % m_GridRouting;
77 end.y += m_GridRouting;
78
79 m_BrdBox.SetEnd( end );
80
83
84 // gives a small margin
85 m_Ncols += 1;
86 m_Nrows += 1;
87
88 return true;
89}
90
91
93{
94 if( m_Nrows <= 0 || m_Ncols <= 0 )
95 return 0;
96
97 // give a small margin for memory allocation:
98 int ii = ( m_Nrows + 1 ) * ( m_Ncols + 1 );
99
100 int side = AR_SIDE_BOTTOM;
101 for( int jj = 0; jj < m_RoutingLayersCount; jj++ ) // m_RoutingLayersCount = 1 or 2
102 {
103 m_BoardSide[side] = nullptr;
104 m_DistSide[side] = nullptr;
105
106 // allocate matrix & initialize everything to empty
107 m_BoardSide[side] = new MATRIX_CELL[ ii * sizeof( MATRIX_CELL ) ];
108 memset( m_BoardSide[side], 0, ii * sizeof( MATRIX_CELL ) );
109
110 if( m_BoardSide[side] == nullptr )
111 return -1;
112
113 // allocate Distances
114 m_DistSide[side] = new DIST_CELL[ ii * sizeof( DIST_CELL ) ];
115 memset( m_DistSide[side], 0, ii * sizeof( DIST_CELL ) );
116
117 if( m_DistSide[side] == nullptr )
118 return -1;
119
120 side = AR_SIDE_TOP;
121 }
122
123 m_MemSize = m_RouteCount * ii * ( sizeof( MATRIX_CELL ) + sizeof( DIST_CELL ) );
124
125 return m_MemSize;
126}
127
128
130{
131 int ii;
132
133 for( ii = 0; ii < AR_MAX_ROUTING_LAYERS_COUNT; ii++ )
134 {
135 // de-allocate Distances matrix
136 if( m_DistSide[ii] )
137 {
138 delete[] m_DistSide[ii];
139 m_DistSide[ii] = nullptr;
140 }
141
142 // de-allocate cells matrix
143 if( m_BoardSide[ii] )
144 {
145 delete[] m_BoardSide[ii];
146 m_BoardSide[ii] = nullptr;
147 }
148 }
149
150 m_Nrows = m_Ncols = 0;
151}
152
153// Initialize m_opWriteCell member to make the aLogicOp
155{
156 switch( aLogicOp )
157 {
158 default:
164 }
165}
166
167
168/* return the value stored in a cell
169 */
170AR_MATRIX::MATRIX_CELL AR_MATRIX::GetCell( int aRow, int aCol, int aSide )
171{
172 MATRIX_CELL* p;
173
174 p = m_BoardSide[aSide];
175 return p[aRow * m_Ncols + aCol];
176}
177
178
179/* basic cell operation : WRITE operation
180 */
181void AR_MATRIX::SetCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
182{
183 MATRIX_CELL* p;
184
185 p = m_BoardSide[aSide];
186 p[aRow * m_Ncols + aCol] = x;
187}
188
189
190/* basic cell operation : OR operation
191 */
192void AR_MATRIX::OrCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
193{
194 MATRIX_CELL* p;
195
196 p = m_BoardSide[aSide];
197 p[aRow * m_Ncols + aCol] |= x;
198}
199
200
201/* basic cell operation : XOR operation
202 */
203void AR_MATRIX::XorCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
204{
205 MATRIX_CELL* p;
206
207 p = m_BoardSide[aSide];
208 p[aRow * m_Ncols + aCol] ^= x;
209}
210
211
212/* basic cell operation : AND operation
213 */
214void AR_MATRIX::AndCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
215{
216 MATRIX_CELL* p;
217
218 p = m_BoardSide[aSide];
219 p[aRow * m_Ncols + aCol] &= x;
220}
221
222
223/* basic cell operation : ADD operation
224 */
225void AR_MATRIX::AddCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
226{
227 MATRIX_CELL* p;
228
229 p = m_BoardSide[aSide];
230 p[aRow * m_Ncols + aCol] += x;
231}
232
233
234// fetch distance cell
235AR_MATRIX::DIST_CELL AR_MATRIX::GetDist( int aRow, int aCol, int aSide ) // fetch distance cell
236{
237 DIST_CELL* p;
238
239 p = m_DistSide[aSide];
240 return p[aRow * m_Ncols + aCol];
241}
242
243
244// store distance cell
245void AR_MATRIX::SetDist( int aRow, int aCol, int aSide, DIST_CELL x )
246{
247 DIST_CELL* p;
248
249 p = m_DistSide[aSide];
250 p[aRow * m_Ncols + aCol] = x;
251}
252
253
254/*
255** x is the direction to enter the cell of interest.
256** y is the direction to exit the cell of interest.
257** z is the direction to really exit the cell, if y=FROM_OTHERSIDE.
258**
259** return the distance of the trace through the cell of interest.
260** the calculation is driven by the tables above.
261*/
262
263
264#define OP_CELL( layer, dy, dx ) \
265 { \
266 if( layer == UNDEFINED_LAYER ) \
267 { \
268 WriteCell( dy, dx, AR_SIDE_BOTTOM, color ); \
269 if( m_RoutingLayersCount > 1 ) \
270 WriteCell( dy, dx, AR_SIDE_TOP, color ); \
271 } \
272 else \
273 { \
274 if( layer == m_routeLayerBottom ) \
275 WriteCell( dy, dx, AR_SIDE_BOTTOM, color ); \
276 if( m_RoutingLayersCount > 1 ) \
277 if( layer == m_routeLayerTop ) \
278 WriteCell( dy, dx, AR_SIDE_TOP, color ); \
279 } \
280 }
281
282/* Fills all cells inside a segment
283 * half-width = lg, org = ux0,uy0 end = ux1,uy1
284 * coordinates are in PCB units
285 */
286void AR_MATRIX::drawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer, int color,
287 AR_MATRIX::CELL_OP op_logic )
288{
289 int64_t row, col;
290 int64_t inc;
291 int64_t row_max, col_max, row_min, col_min;
292 int64_t demi_pas;
293
294 int cx, cy, dx, dy;
295
296 SetCellOperation( op_logic );
297
298 // Make coordinate ux1 tj > ux0 to simplify calculations
299 if( ux1 < ux0 )
300 {
301 std::swap( ux1, ux0 );
302 std::swap( uy1, uy0 );
303 }
304
305 // Calculating the incrementing the Y axis
306 inc = 1;
307
308 if( uy1 < uy0 )
309 inc = -1;
310
311 demi_pas = m_GridRouting / 2;
312
313 col_min = ( ux0 - lg ) / m_GridRouting;
314
315 if( col_min < 0 )
316 col_min = 0;
317
318 col_max = ( ux1 + lg + demi_pas ) / m_GridRouting;
319
320 if( col_max > ( m_Ncols - 1 ) )
321 col_max = m_Ncols - 1;
322
323 if( inc > 0 )
324 {
325 row_min = ( uy0 - lg ) / m_GridRouting;
326 row_max = ( uy1 + lg + demi_pas ) / m_GridRouting;
327 }
328 else
329 {
330 row_min = ( uy1 - lg ) / m_GridRouting;
331 row_max = ( uy0 + lg + demi_pas ) / m_GridRouting;
332 }
333
334 if( row_min < 0 )
335 row_min = 0;
336
337 if( row_min > ( m_Nrows - 1 ) )
338 row_min = m_Nrows - 1;
339
340 if( row_max < 0 )
341 row_max = 0;
342
343 if( row_max > ( m_Nrows - 1 ) )
344 row_max = m_Nrows - 1;
345
346 dx = ux1 - ux0;
347 dy = uy1 - uy0;
348
349 EDA_ANGLE angle( VECTOR2I( dx, dy ) );
350
351 RotatePoint( &dx, &dy, angle ); // dx = length, dy = 0
352
353 for( col = col_min; col <= col_max; col++ )
354 {
355 int64_t cxr;
356 cxr = ( col * m_GridRouting ) - ux0;
357
358 for( row = row_min; row <= row_max; row++ )
359 {
360 cy = ( row * m_GridRouting ) - uy0;
361 cx = cxr;
362 RotatePoint( &cx, &cy, angle );
363
364 if( abs( cy ) > lg )
365 continue; // The point is too far on the Y axis.
366
367 /* This point a test is close to the segment: the position
368 * along the X axis must be tested.
369 */
370 if( ( cx >= 0 ) && ( cx <= dx ) )
371 {
372 OP_CELL( layer, row, col );
373 continue;
374 }
375
376 // Examination of extremities are rounded.
377 if( ( cx < 0 ) && ( cx >= -lg ) )
378 {
379 if( ( ( cx * cx ) + ( cy * cy ) ) <= ( lg * lg ) )
380 OP_CELL( layer, row, col );
381
382 continue;
383 }
384
385 if( ( cx > dx ) && ( cx <= ( dx + lg ) ) )
386 {
387 if( ( ( ( cx - dx ) * ( cx - dx ) ) + ( cy * cy ) ) <= ( lg * lg ) )
388 OP_CELL( layer, row, col );
389
390 continue;
391 }
392 }
393 }
394}
395
396
397/* Fills all cells of the routing matrix contained in the circle
398 * half-width = lg, center = ux0, uy0, ux1,uy1 is a point on the circle.
399 * coord are in PCB units.
400 */
401void AR_MATRIX::traceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer, int color,
402 AR_MATRIX::CELL_OP op_logic )
403{
404 int radius, nb_segm;
405 int x0, y0; // Starting point of the current segment trace.
406 int x1, y1; // End point.
407 int ii;
408
409 radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
410
411 x0 = x1 = radius;
412 y0 = y1 = 0;
413
414 if( lg < 1 )
415 lg = 1;
416
417 nb_segm = ( 2 * radius ) / lg;
418
419 if( nb_segm < 5 )
420 nb_segm = 5;
421
422 if( nb_segm > 100 )
423 nb_segm = 100;
424
425 for( ii = 1; ii < nb_segm; ii++ )
426 {
427 EDA_ANGLE angle = ( ANGLE_360 * ii ) / nb_segm;
428 x1 = KiROUND( radius * angle.Cos() );
429 y1 = KiROUND( radius * angle.Sin() );
430 drawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
431 x0 = x1;
432 y0 = y1;
433 }
434
435 drawSegmentQcq( x1 + ux0, y1 + uy0, ux0 + radius, uy0, lg, layer, color, op_logic );
436}
437
438
440 int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic )
441{
442 int row, col;
443 int ux0, uy0, ux1, uy1;
444 int row_max, col_max, row_min, col_min;
445 int trace = 0;
446 double fdistmin, fdistx, fdisty;
447 int tstwrite = 0;
448 int distmin;
449
450 if( aLayerMask[m_routeLayerBottom] )
451 trace = 1; // Trace on BOTTOM
452
453 if( aLayerMask[m_routeLayerTop] )
454 if( m_RoutingLayersCount > 1 )
455 trace |= 2; // Trace on TOP
456
457 if( trace == 0 )
458 return;
459
460 SetCellOperation( op_logic );
461
462 cx -= GetBrdCoordOrigin().x;
463 cy -= GetBrdCoordOrigin().y;
464
465 distmin = radius;
466
467 // Calculate the bounding rectangle of the circle.
468 ux0 = cx - radius;
469 uy0 = cy - radius;
470 ux1 = cx + radius;
471 uy1 = cy + radius;
472
473 // Calculate limit coordinates of cells belonging to the rectangle.
474 row_max = uy1 / m_GridRouting;
475 col_max = ux1 / m_GridRouting;
476 row_min = uy0 / m_GridRouting; // if (uy0 > row_min*Board.m_GridRouting) row_min++;
477 col_min = ux0 / m_GridRouting; // if (ux0 > col_min*Board.m_GridRouting) col_min++;
478
479 if( row_min < 0 )
480 row_min = 0;
481
482 if( row_max >= ( m_Nrows - 1 ) )
483 row_max = m_Nrows - 1;
484
485 if( col_min < 0 )
486 col_min = 0;
487
488 if( col_max >= ( m_Ncols - 1 ) )
489 col_max = m_Ncols - 1;
490
491 // Calculate coordinate limits of cell belonging to the rectangle.
492 if( row_min > row_max )
493 row_max = row_min;
494
495 if( col_min > col_max )
496 col_max = col_min;
497
498 fdistmin = (double) distmin * distmin;
499
500 for( row = row_min; row <= row_max; row++ )
501 {
502 fdisty = (double) ( cy - ( row * m_GridRouting ) );
503 fdisty *= fdisty;
504
505 for( col = col_min; col <= col_max; col++ )
506 {
507 fdistx = (double) ( cx - ( col * m_GridRouting ) );
508 fdistx *= fdistx;
509
510 if( fdistmin <= ( fdistx + fdisty ) )
511 continue;
512
513 if( trace & 1 )
514 WriteCell( row, col, AR_SIDE_BOTTOM, color );
515
516 if( trace & 2 )
517 WriteCell( row, col, AR_SIDE_TOP, color );
518
519 tstwrite = 1;
520 }
521 }
522
523 if( tstwrite )
524 return;
525
526 /* If no cell has been written, it affects the 4 neighboring diagonal
527 * (Adverse event: pad off grid in the center of the 4 neighboring
528 * diagonal) */
529 distmin = m_GridRouting / 2 + 1;
530 fdistmin = ( (double) distmin * distmin ) * 2; // Distance to center point diagonally
531
532 for( row = row_min; row <= row_max; row++ )
533 {
534 fdisty = (double) ( cy - ( row * m_GridRouting ) );
535 fdisty *= fdisty;
536
537 for( col = col_min; col <= col_max; col++ )
538 {
539 fdistx = (double) ( cx - ( col * m_GridRouting ) );
540 fdistx *= fdistx;
541
542 if( fdistmin <= ( fdistx + fdisty ) )
543 continue;
544
545 if( trace & 1 )
546 WriteCell( row, col, AR_SIDE_BOTTOM, color );
547
548 if( trace & 2 )
549 WriteCell( row, col, AR_SIDE_TOP, color );
550 }
551 }
552}
553
554
555/* Fills all routing matrix cells contained in the arc
556 * angle = ArcAngle, half-width lg
557 * center = ux0,uy0, starting at ux1, uy1. Coordinates are in
558 * PCB units.
559 */
560void AR_MATRIX::traceArc( int ux0, int uy0, int ux1, int uy1, const EDA_ANGLE& arcAngle, int lg,
561 int layer, int color, AR_MATRIX::CELL_OP op_logic )
562{
563 int radius, nb_segm;
564 int x0, y0; // Starting point of the current segment trace
565 int x1, y1; // End point
566 int ii;
567 EDA_ANGLE angle, startAngle;
568
569 radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
570
571 x0 = ux1 - ux0;
572 y0 = uy1 - uy0;
573 startAngle = EDA_ANGLE( VECTOR2I( ux1, uy1 ) - VECTOR2I( ux0, uy0 ) );
574
575 if( lg < 1 )
576 lg = 1;
577
578 nb_segm = ( 2 * radius ) / lg;
579 nb_segm = nb_segm * std::abs( arcAngle.AsDegrees() ) / 360.0;
580
581 if( nb_segm < 5 )
582 nb_segm = 5;
583
584 if( nb_segm > 100 )
585 nb_segm = 100;
586
587 for( ii = 1; ii <= nb_segm; ii++ )
588 {
589 angle = arcAngle * ii / nb_segm;
590 angle += startAngle;
591
592 angle.Normalize();
593
594 x1 = KiROUND( radius * angle.Cos() );
595 y1 = KiROUND( radius * angle.Cos() );
596 drawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
597 x0 = x1;
598 y0 = y1;
599 }
600}
601
602
603void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, double angle,
604 LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic )
605{
606 int row, col;
607 int cx, cy; // Center of rectangle
608 int radius; // Radius of the circle
609 int row_min, row_max, col_min, col_max;
610 int rotrow, rotcol;
611 int trace = 0;
612
613 if( aLayerMask[m_routeLayerBottom] )
614 trace = 1; // Trace on BOTTOM
615
616 if( aLayerMask[m_routeLayerTop] )
617 {
618 if( m_RoutingLayersCount > 1 )
619 trace |= 2; // Trace on TOP
620 }
621
622 if( trace == 0 )
623 return;
624
625 SetCellOperation( op_logic );
626
627 ux0 -= GetBrdCoordOrigin().x;
628 uy0 -= GetBrdCoordOrigin().y;
629 ux1 -= GetBrdCoordOrigin().x;
630 uy1 -= GetBrdCoordOrigin().y;
631
632 cx = ( ux0 + ux1 ) / 2;
633 cy = ( uy0 + uy1 ) / 2;
634 radius = KiROUND( Distance( ux0, uy0, cx, cy ) );
635
636 // Calculating coordinate limits belonging to the rectangle.
637 row_max = ( cy + radius ) / m_GridRouting;
638 col_max = ( cx + radius ) / m_GridRouting;
639 row_min = ( cy - radius ) / m_GridRouting;
640
641 if( uy0 > row_min * m_GridRouting )
642 row_min++;
643
644 col_min = ( cx - radius ) / m_GridRouting;
645
646 if( ux0 > col_min * m_GridRouting )
647 col_min++;
648
649 if( row_min < 0 )
650 row_min = 0;
651
652 if( row_max >= ( m_Nrows - 1 ) )
653 row_max = m_Nrows - 1;
654
655 if( col_min < 0 )
656 col_min = 0;
657
658 if( col_max >= ( m_Ncols - 1 ) )
659 col_max = m_Ncols - 1;
660
661 for( row = row_min; row <= row_max; row++ )
662 {
663 for( col = col_min; col <= col_max; col++ )
664 {
665 rotrow = row * m_GridRouting;
666 rotcol = col * m_GridRouting;
667 RotatePoint( &rotcol, &rotrow, cx, cy, -EDA_ANGLE( angle, TENTHS_OF_A_DEGREE_T ) );
668
669 if( rotrow <= uy0 )
670 continue;
671
672 if( rotrow >= uy1 )
673 continue;
674
675 if( rotcol <= ux0 )
676 continue;
677
678 if( rotcol >= ux1 )
679 continue;
680
681 if( trace & 1 )
682 WriteCell( row, col, AR_SIDE_BOTTOM, color );
683
684 if( trace & 2 )
685 WriteCell( row, col, AR_SIDE_TOP, color );
686 }
687 }
688}
689
690
691void AR_MATRIX::TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, LSET aLayerMask,
692 int color, AR_MATRIX::CELL_OP op_logic )
693{
694 int row, col;
695 int row_min, row_max, col_min, col_max;
696 int trace = 0;
697
698 if( aLayerMask[m_routeLayerBottom] )
699 trace = 1; // Trace on BOTTOM
700
701 if( aLayerMask[m_routeLayerTop] && m_RoutingLayersCount > 1 )
702 trace |= 2; // Trace on TOP
703
704 if( trace == 0 )
705 return;
706
707 SetCellOperation( op_logic );
708
709 ux0 -= GetBrdCoordOrigin().x;
710 uy0 -= GetBrdCoordOrigin().y;
711 ux1 -= GetBrdCoordOrigin().x;
712 uy1 -= GetBrdCoordOrigin().y;
713
714 // Calculating limits coord cells belonging to the rectangle.
715 row_max = uy1 / m_GridRouting;
716 col_max = ux1 / m_GridRouting;
717 row_min = uy0 / m_GridRouting;
718
719 if( uy0 > row_min * m_GridRouting )
720 row_min++;
721
722 col_min = ux0 / m_GridRouting;
723
724 if( ux0 > col_min * m_GridRouting )
725 col_min++;
726
727 if( row_min < 0 )
728 row_min = 0;
729
730 if( row_max >= ( m_Nrows - 1 ) )
731 row_max = m_Nrows - 1;
732
733 if( col_min < 0 )
734 col_min = 0;
735
736 if( col_max >= ( m_Ncols - 1 ) )
737 col_max = m_Ncols - 1;
738
739 for( row = row_min; row <= row_max; row++ )
740 {
741 for( col = col_min; col <= col_max; col++ )
742 {
743 if( trace & 1 )
744 WriteCell( row, col, AR_SIDE_BOTTOM, color );
745
746 if( trace & 2 )
747 WriteCell( row, col, AR_SIDE_TOP, color );
748 }
749 }
750}
751
752
753void AR_MATRIX::TraceSegmentPcb( PCB_SHAPE* aShape, int aColor, int aMargin,
754 AR_MATRIX::CELL_OP op_logic )
755{
756 int half_width = ( aShape->GetWidth() / 2 ) + aMargin;
757
758 // Calculate the bounding rectangle of the segment (if H, V or Via)
759 int layer = UNDEFINED_LAYER; // Draw on all layers
760
761 if( aShape->GetShape() == SHAPE_T::CIRCLE || aShape->GetShape() == SHAPE_T::SEGMENT )
762 {
763 int ux0 = aShape->GetStart().x - GetBrdCoordOrigin().x;
764 int uy0 = aShape->GetStart().y - GetBrdCoordOrigin().y;
765 int ux1 = aShape->GetEnd().x - GetBrdCoordOrigin().x;
766 int uy1 = aShape->GetEnd().y - GetBrdCoordOrigin().y;
767
768 if( aShape->GetShape() == SHAPE_T::CIRCLE )
769 traceCircle( ux0, uy0, ux1, uy1, half_width, layer, aColor, op_logic );
770 else
771 drawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, aColor, op_logic );
772 }
773 else if( aShape->GetShape() == SHAPE_T::ARC )
774 {
775 int ux0 = aShape->GetCenter().x - GetBrdCoordOrigin().x;
776 int uy0 = aShape->GetCenter().y - GetBrdCoordOrigin().y;
777 int ux1 = aShape->GetStart().x - GetBrdCoordOrigin().x;
778 int uy1 = aShape->GetStart().y - GetBrdCoordOrigin().y;
779
780 traceArc( ux0, uy0, ux1, uy1, aShape->GetArcAngle(), half_width, layer, aColor, op_logic );
781 }
782}
783
784
796 int ux0, int uy0, int ux1, int uy1, int marge, int aKeepOut, LSET aLayerMask )
797{
798 int row, col;
799 int row_min, row_max, col_min, col_max, pmarge;
800 int trace = 0;
801 DIST_CELL data, LocalKeepOut;
802 int lgain, cgain;
803
804 if( aLayerMask[m_routeLayerBottom] )
805 trace = 1; // Trace on bottom layer.
806
807 if( aLayerMask[m_routeLayerTop] && m_RoutingLayersCount )
808 trace |= 2; // Trace on top layer.
809
810 if( trace == 0 )
811 return;
812
813 ux0 -= m_BrdBox.GetX();
814 uy0 -= m_BrdBox.GetY();
815 ux1 -= m_BrdBox.GetX();
816 uy1 -= m_BrdBox.GetY();
817
818 ux0 -= marge;
819 ux1 += marge;
820 uy0 -= marge;
821 uy1 += marge;
822
823 pmarge = marge / m_GridRouting;
824
825 if( pmarge < 1 )
826 pmarge = 1;
827
828 // Calculate the coordinate limits of the rectangle.
829 row_max = uy1 / m_GridRouting;
830 col_max = ux1 / m_GridRouting;
831 row_min = uy0 / m_GridRouting;
832
833 if( uy0 > row_min * m_GridRouting )
834 row_min++;
835
836 col_min = ux0 / m_GridRouting;
837
838 if( ux0 > col_min * m_GridRouting )
839 col_min++;
840
841 if( row_min < 0 )
842 row_min = 0;
843
844 if( row_max >= ( m_Nrows - 1 ) )
845 row_max = m_Nrows - 1;
846
847 if( col_min < 0 )
848 col_min = 0;
849
850 if( col_max >= ( m_Ncols - 1 ) )
851 col_max = m_Ncols - 1;
852
853 for( row = row_min; row <= row_max; row++ )
854 {
855 lgain = 256;
856
857 if( row < pmarge )
858 lgain = ( 256 * row ) / pmarge;
859 else if( row > row_max - pmarge )
860 lgain = ( 256 * ( row_max - row ) ) / pmarge;
861
862 for( col = col_min; col <= col_max; col++ )
863 {
864 // RoutingMatrix Dist map contained the "cost" of the cell
865 // at position (row, col)
866 // in autoplace this is the cost of the cell, when
867 // a footprint overlaps it, near a "master" footprint
868 // this cost is high near the "master" footprint
869 // and decrease with the distance
870 cgain = 256;
871 LocalKeepOut = aKeepOut;
872
873 if( col < pmarge )
874 cgain = ( 256 * col ) / pmarge;
875 else if( col > col_max - pmarge )
876 cgain = ( 256 * ( col_max - col ) ) / pmarge;
877
878 cgain = ( cgain * lgain ) / 256;
879
880 if( cgain != 256 )
881 LocalKeepOut = ( LocalKeepOut * cgain ) / 256;
882
883 if( trace & 1 )
884 {
885 data = GetDist( row, col, AR_SIDE_BOTTOM ) + LocalKeepOut;
886 SetDist( row, col, AR_SIDE_BOTTOM, data );
887 }
888
889 if( trace & 2 )
890 {
891 data = GetDist( row, col, AR_SIDE_TOP );
892 data = std::max( data, LocalKeepOut );
893 SetDist( row, col, AR_SIDE_TOP, data );
894 }
895 }
896 }
897}
898
899
900void AR_MATRIX::PlacePad( PAD* aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic )
901{
902 int dx, dy;
903 VECTOR2I shape_pos = aPad->ShapePos();
904
905 dx = aPad->GetSize().x / 2;
906 dx += marge;
907
908 if( aPad->GetShape() == PAD_SHAPE::CIRCLE )
909 {
910 traceFilledCircle( shape_pos.x, shape_pos.y, dx, aPad->GetLayerSet(), color, op_logic );
911 return;
912 }
913
914 dy = aPad->GetSize().y / 2;
915 dy += marge;
916
917 if( aPad->GetShape() == PAD_SHAPE::TRAPEZOID )
918 {
919 dx += abs( aPad->GetDelta().y ) / 2;
920 dy += abs( aPad->GetDelta().x ) / 2;
921 }
922
923 // The pad is a rectangle ( horizontal or vertical )
924 if( aPad->GetOrientation().IsCardinal() )
925 {
926 // Orientation turned 90 deg.
927 if( aPad->GetOrientation() == ANGLE_90 || aPad->GetOrientation() == ANGLE_270 )
928 {
929 std::swap( dx, dy );
930 }
931
932 TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy, shape_pos.x + dx,
933 shape_pos.y + dy, aPad->GetLayerSet(), color, op_logic );
934 }
935 else
936 {
937 TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy, shape_pos.x + dx,
938 shape_pos.y + dy, aPad->GetOrientation().AsTenthsOfADegree(),
939 aPad->GetLayerSet(), color, op_logic );
940 }
941}
int color
Definition: DXF_plotter.cpp:58
#define OP_CELL(layer, dy, dx)
Definition: ar_matrix.cpp:264
#define AR_SIDE_BOTTOM
Definition: ar_matrix.h:42
#define AR_MAX_ROUTING_LAYERS_COUNT
Definition: ar_matrix.h:39
#define AR_SIDE_TOP
Definition: ar_matrix.h:41
void UnInitRoutingMatrix()
Definition: ar_matrix.cpp:129
int m_Nrows
Definition: ar_matrix.h:144
unsigned char MATRIX_CELL
Definition: ar_matrix.h:50
BOX2I m_BrdBox
Definition: ar_matrix.h:143
void AddCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:225
void AndCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:214
void SetCellOperation(CELL_OP aLogicOp)
Definition: ar_matrix.cpp:154
void(AR_MATRIX::* m_opWriteCell)(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:153
void TraceSegmentPcb(PCB_SHAPE *aShape, int aColor, int aMargin, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:753
int m_RouteCount
Definition: ar_matrix.h:146
int DIST_CELL
Definition: ar_matrix.h:51
int m_RoutingLayersCount
Definition: ar_matrix.h:141
void SetCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:181
@ WRITE_OR_CELL
Definition: ar_matrix.h:56
@ WRITE_AND_CELL
Definition: ar_matrix.h:58
@ WRITE_XOR_CELL
Definition: ar_matrix.h:57
@ WRITE_CELL
Definition: ar_matrix.h:55
@ WRITE_ADD_CELL
Definition: ar_matrix.h:59
void XorCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:203
void SetDist(int aRow, int aCol, int aSide, DIST_CELL)
Definition: ar_matrix.cpp:245
int m_MemSize
Definition: ar_matrix.h:145
PCB_LAYER_ID m_routeLayerBottom
Definition: ar_matrix.h:149
int InitRoutingMatrix()
Initialize the data structures.
Definition: ar_matrix.cpp:92
MATRIX_CELL * m_BoardSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:138
void drawSegmentQcq(int ux0, int uy0, int ux1, int uy1, int lg, int layer, int color, CELL_OP op_logic)
Definition: ar_matrix.cpp:286
bool ComputeMatrixSize(const BOX2I &aBoundingBox)
Calculate the number of rows and columns of dimensions of aPcb for routing and automatic calculation ...
Definition: ar_matrix.cpp:62
void OrCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.cpp:192
int m_GridRouting
Definition: ar_matrix.h:142
void traceCircle(int ux0, int uy0, int ux1, int uy1, int lg, int layer, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:401
DIST_CELL * m_DistSide[AR_MAX_ROUTING_LAYERS_COUNT]
Definition: ar_matrix.h:139
DIST_CELL GetDist(int aRow, int aCol, int aSide)
Definition: ar_matrix.cpp:235
MATRIX_CELL GetCell(int aRow, int aCol, int aSide)
Definition: ar_matrix.cpp:170
void traceArc(int ux0, int uy0, int ux1, int uy1, const EDA_ANGLE &arcAngle, int lg, int layer, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:560
void traceFilledCircle(int cx, int cy, int radius, LSET aLayerMask, int color, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:439
VECTOR2I GetBrdCoordOrigin()
Definition: ar_matrix.h:74
void WriteCell(int aRow, int aCol, int aSide, MATRIX_CELL aCell)
Definition: ar_matrix.h:65
int m_Ncols
Definition: ar_matrix.h:144
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:603
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:795
void PlacePad(PAD *aPad, int color, int marge, AR_MATRIX::CELL_OP op_logic)
Definition: ar_matrix.cpp:900
PCB_LAYER_ID m_routeLayerTop
Definition: ar_matrix.h:148
size_type GetHeight() const
Definition: box2.h:205
void SetX(coord_type val)
Definition: box2.h:260
void SetY(coord_type val)
Definition: box2.h:265
size_type GetWidth() const
Definition: box2.h:204
coord_type GetY() const
Definition: box2.h:198
const Vec GetEnd() const
Definition: box2.h:202
coord_type GetX() const
Definition: box2.h:197
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:280
EDA_ANGLE Normalize()
Definition: eda_angle.h:255
double Sin() const
Definition: eda_angle.h:212
int AsTenthsOfADegree() const
Definition: eda_angle.h:157
double AsDegrees() const
Definition: eda_angle.h:155
bool IsCardinal() const
Definition: eda_angle.cpp:40
double Cos() const
Definition: eda_angle.h:227
EDA_ANGLE GetArcAngle() const
Definition: eda_shape.cpp:663
SHAPE_T GetShape() const
Definition: eda_shape.h:120
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:150
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:125
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
Definition: pad.h:59
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pad.h:374
VECTOR2I ShapePos() const
Definition: pad.cpp:944
const VECTOR2I & GetDelta() const
Definition: pad.h:254
PAD_SHAPE GetShape() const
Definition: pad.h:193
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition: pad.h:345
const VECTOR2I & GetSize() const
Definition: pad.h:247
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:75
int GetWidth() const override
Definition: pcb_shape.cpp:367
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:440
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:441
@ B_Cu
Definition: layer_ids.h:95
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228
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:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588