2011-09-20 13:57:40 +00:00
|
|
|
/**
|
|
|
|
* @file graphpcb.cpp
|
|
|
|
* @brief PCB editor autorouting and "graphics" routines.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "pcbcommon.h"
|
|
|
|
|
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_track.h"
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "cell.h"
|
2011-09-20 13:57:40 +00:00
|
|
|
#include "ar_protos.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
int ToMatrixCoordinate( int aPhysicalCoordinate );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
|
|
|
void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color );
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
void TraceArc( int ux0,
|
|
|
|
int uy0,
|
|
|
|
int ux1,
|
|
|
|
int uy1,
|
|
|
|
int ArcAngle,
|
|
|
|
int lg,
|
|
|
|
int layer,
|
|
|
|
int color,
|
2011-09-20 13:57:40 +00:00
|
|
|
int op_logic );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void DrawSegmentQcq( int ux0,
|
|
|
|
int uy0,
|
|
|
|
int ux1,
|
|
|
|
int uy1,
|
|
|
|
int lg,
|
|
|
|
int layer,
|
|
|
|
int color,
|
2011-09-20 13:57:40 +00:00
|
|
|
int op_logic );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
static void TraceFilledCircle( BOARD* Pcb,
|
2009-11-14 22:15:22 +00:00
|
|
|
int cx,
|
|
|
|
int cy,
|
2011-03-09 14:30:39 +00:00
|
|
|
int radius,
|
2011-09-07 19:41:04 +00:00
|
|
|
int aLayerMask,
|
2009-11-14 22:15:22 +00:00
|
|
|
int color,
|
2011-09-20 13:57:40 +00:00
|
|
|
int op_logic );
|
|
|
|
|
|
|
|
static void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
|
|
|
|
int color, int op_logic );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
/* Macro call to update cell. */
|
|
|
|
#define OP_CELL( layer, dy, dx ) \
|
|
|
|
{ \
|
|
|
|
if( layer < 0 ) \
|
|
|
|
{ \
|
|
|
|
WriteCell( dy, dx, BOTTOM, color ); \
|
|
|
|
if( Nb_Sides ) \
|
|
|
|
WriteCell( dy, dx, TOP, color ); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
if( layer == Route_Layer_BOTTOM ) \
|
|
|
|
WriteCell( dy, dx, BOTTOM, color ); \
|
|
|
|
if( Nb_Sides ) \
|
|
|
|
if( layer == Route_Layer_TOP ) \
|
|
|
|
WriteCell( dy, dx, TOP, color ); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function ToMatrixCoordinate
|
2008-09-12 10:31:32 +00:00
|
|
|
* compute the coordinate in the routing matrix from the real (board) value
|
|
|
|
* @param aPhysicalCoordinate = value to convert
|
|
|
|
* @return the coordinate relative to the matrix
|
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
int ToMatrixCoordinate( int aPhysicalCoordinate )
|
2008-09-12 10:31:32 +00:00
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
return aPhysicalCoordinate / Board.m_GridRouting;
|
2008-09-12 10:31:32 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
void PlacePad( BOARD* Pcb, D_PAD* pt_pad, int color, int marge, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
int dx, dy;
|
2011-03-03 19:08:13 +00:00
|
|
|
wxPoint shape_pos = pt_pad->ReturnShapePos();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
dx = pt_pad->m_Size.x / 2;
|
|
|
|
dx += marge;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-01-05 17:30:56 +00:00
|
|
|
if( pt_pad->m_PadShape == PAD_CIRCLE )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
TraceFilledCircle( Pcb, shape_pos.x, shape_pos.y, dx,
|
|
|
|
pt_pad->m_layerMask, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
dy = pt_pad->m_Size.y / 2;
|
|
|
|
dy += marge;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-01-05 17:30:56 +00:00
|
|
|
if( pt_pad->m_PadShape == PAD_TRAPEZOID )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
dx += abs( pt_pad->m_DeltaSize.y ) / 2;
|
|
|
|
dy += abs( pt_pad->m_DeltaSize.x ) / 2;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( ( pt_pad->m_Orient % 900 ) == 0 ) /* The pad is a rectangle
|
|
|
|
* horizontally or vertically. */
|
|
|
|
{
|
|
|
|
/* Orientation turned 90 deg. */
|
|
|
|
if( ( pt_pad->m_Orient == 900 ) || ( pt_pad->m_Orient == 2700 ) )
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
EXCHG( dx, dy );
|
|
|
|
}
|
|
|
|
|
|
|
|
TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy,
|
|
|
|
shape_pos.x + dx, shape_pos.y + dy,
|
2011-09-20 13:57:40 +00:00
|
|
|
pt_pad->m_layerMask, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy,
|
|
|
|
shape_pos.x + dx, shape_pos.y + dy,
|
|
|
|
(int) pt_pad->m_Orient,
|
2011-09-20 13:57:40 +00:00
|
|
|
pt_pad->m_layerMask, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
/* Initialize a color value, the cells included in the board area of the
|
2009-11-14 22:15:22 +00:00
|
|
|
* circle center cx, cy.
|
|
|
|
* Parameters:
|
|
|
|
* radius: a value add to the radius or half the score pad
|
2011-09-07 19:41:04 +00:00
|
|
|
* aLayerMask: layer occupied
|
2009-11-14 22:15:22 +00:00
|
|
|
* color: mask write in cells
|
2011-09-20 13:57:40 +00:00
|
|
|
* op_logic: type of writing in the cell (WRITE, OR)
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-09-20 13:57:40 +00:00
|
|
|
void TraceFilledCircle( BOARD* Pcb,
|
2009-11-14 22:15:22 +00:00
|
|
|
int cx,
|
|
|
|
int cy,
|
2011-03-09 14:30:39 +00:00
|
|
|
int radius,
|
2011-09-07 19:41:04 +00:00
|
|
|
int aLayerMask,
|
2009-11-14 22:15:22 +00:00
|
|
|
int color,
|
2011-09-20 13:57:40 +00:00
|
|
|
int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
int row, col;
|
|
|
|
int ux0, uy0, ux1, uy1;
|
|
|
|
int row_max, col_max, row_min, col_min;
|
|
|
|
int trace = 0;
|
|
|
|
float fdistmin, fdistx, fdisty;
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
void (* WriteCell)( int, int, int, MATRIX_CELL );
|
2007-08-23 04:28:46 +00:00
|
|
|
int tstwrite = 0;
|
|
|
|
int distmin;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Determine occupied layer. */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Single routing layer on bitmap and BOTTOM
|
|
|
|
* Route_Layer_B = Route_Layer_A */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] )
|
2009-11-14 22:15:22 +00:00
|
|
|
trace = 1; /* Trace on BOTTOM */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] )
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Nb_Sides )
|
2009-11-14 22:15:22 +00:00
|
|
|
trace |= 2; /* Trace on TOP */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( trace == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
switch( op_logic )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case WRITE_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = SetCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_OR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = OrCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_XOR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = XorCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_AND_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AndCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_ADD_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AddCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
cx -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
cy -= Pcb->m_BoundaryBox.m_Pos.y;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
distmin = radius;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate the bounding rectangle of the circle. */
|
2011-03-09 14:30:39 +00:00
|
|
|
ux0 = cx - radius;
|
|
|
|
uy0 = cy - radius;
|
|
|
|
ux1 = cx + radius;
|
|
|
|
uy1 = cy + radius;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate limit coordinates of cells belonging to the rectangle. */
|
2011-03-09 20:09:11 +00:00
|
|
|
row_max = uy1 / Board.m_GridRouting;
|
|
|
|
col_max = ux1 / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
row_min = uy0 / Board.m_GridRouting; // if (uy0 > row_min*Board.m_GridRouting) row_min++;
|
|
|
|
col_min = ux0 / Board.m_GridRouting; // if (ux0 > col_min*Board.m_GridRouting) col_min++;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( row_max >= (Nrows - 1) )
|
|
|
|
row_max = Nrows - 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( col_max >= (Ncols - 1) )
|
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate coordinate limits of cell belonging to the rectangle. */
|
2007-08-23 04:28:46 +00:00
|
|
|
if( row_min > row_max )
|
|
|
|
row_max = row_min;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( col_min > col_max )
|
|
|
|
col_max = col_min;
|
|
|
|
|
|
|
|
fdistmin = (float) distmin * distmin;
|
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
fdisty = (float) ( cy - ( row * Board.m_GridRouting ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fdisty *= fdisty;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
fdistx = (float) ( cx - ( col * Board.m_GridRouting ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fdistx *= fdistx;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( fdistmin <= ( fdistx + fdisty ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( trace & 1 )
|
|
|
|
WriteCell( row, col, BOTTOM, color );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( trace & 2 )
|
|
|
|
WriteCell( row, col, TOP, color );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
tstwrite = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( tstwrite )
|
|
|
|
return;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* If no cell has been written, it affects the 4 neighboring diagonal
|
|
|
|
* (Adverse event: pad off grid in the center of the 4 neighboring
|
|
|
|
* diagonal) */
|
2011-03-09 20:09:11 +00:00
|
|
|
distmin = Board.m_GridRouting / 2 + 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
fdistmin = ( (float) distmin * distmin ) * 2; /* Distance to center point diagonally */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
fdisty = (float) ( cy - ( row * Board.m_GridRouting ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fdisty *= fdisty;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
fdistx = (float) ( cx - ( col * Board.m_GridRouting ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
fdistx *= fdistx;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( fdistmin <= ( fdistx + fdisty ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( trace & 1 )
|
|
|
|
WriteCell( row, col, BOTTOM, color );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( trace & 2 )
|
|
|
|
WriteCell( row, col, TOP, color );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
void TraceSegmentPcb( BOARD* Pcb, TRACK* pt_segm, int color, int marge, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
int half_width;
|
2007-08-23 04:28:46 +00:00
|
|
|
int ux0, uy0, ux1, uy1;
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
half_width = ( pt_segm->m_Width / 2 ) + marge;
|
2011-05-13 13:15:28 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculate the bounding rectangle of the segment (if H, V or Via) */
|
2007-08-23 04:28:46 +00:00
|
|
|
ux0 = pt_segm->m_Start.x - Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy0 = pt_segm->m_Start.y - Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
ux1 = pt_segm->m_End.x - Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy1 = pt_segm->m_End.y - Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Test if VIA (filled circle was drawn) */
|
2011-10-01 19:24:27 +00:00
|
|
|
if( pt_segm->Type() == PCB_VIA_T )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
int mask_layer = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( pt_segm->IsOnLayer( Route_Layer_BOTTOM ) )
|
2008-12-04 04:28:11 +00:00
|
|
|
mask_layer = 1 << Route_Layer_BOTTOM;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( pt_segm->IsOnLayer( Route_Layer_TOP ) )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( mask_layer == 0 )
|
2008-12-04 04:28:11 +00:00
|
|
|
mask_layer = 1 << Route_Layer_TOP;
|
2009-11-14 22:15:22 +00:00
|
|
|
else
|
|
|
|
mask_layer = -1;
|
2008-12-04 04:28:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( color == VIA_IMPOSSIBLE )
|
|
|
|
mask_layer = -1;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( mask_layer )
|
2011-09-20 13:57:40 +00:00
|
|
|
TraceFilledCircle( Pcb, pt_segm->m_Start.x, pt_segm->m_Start.y,
|
|
|
|
half_width, mask_layer, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-05 14:57:24 +00:00
|
|
|
int layer = pt_segm->GetLayer();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2008-03-05 14:57:24 +00:00
|
|
|
if( color == VIA_IMPOSSIBLE )
|
|
|
|
layer = -1;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* The segment is here a straight line or a circle or an arc.: */
|
2007-08-23 04:28:46 +00:00
|
|
|
if( pt_segm->m_Shape == S_CIRCLE )
|
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
TraceCircle( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pt_segm->m_Shape == S_ARC )
|
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
TraceArc( ux0, uy0, ux1, uy1, pt_segm->m_Param, half_width, layer, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* The segment is here a line segment. */
|
|
|
|
if( ( ux0 != ux1 ) && ( uy0 != uy1 ) ) // Segment tilts.
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
DrawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
// The segment is horizontal or vertical.
|
|
|
|
// F4EXB 051018-01
|
2011-09-20 13:57:40 +00:00
|
|
|
DrawSegmentQcq( ux0, uy0, ux1, uy1, half_width, layer, color, op_logic );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Draws a line, if layer = -1 on all layers
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-09-20 13:57:40 +00:00
|
|
|
void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
int dx, dy, lim;
|
|
|
|
int cumul, inc, il, delta;
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
void (* WriteCell)( int, int, int, MATRIX_CELL );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
switch( op_logic )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case WRITE_CELL:
|
|
|
|
WriteCell = SetCell; break;
|
|
|
|
|
|
|
|
case WRITE_OR_CELL:
|
|
|
|
WriteCell = OrCell; break;
|
|
|
|
|
|
|
|
case WRITE_XOR_CELL:
|
|
|
|
WriteCell = XorCell; break;
|
|
|
|
|
|
|
|
case WRITE_AND_CELL:
|
|
|
|
WriteCell = AndCell; break;
|
|
|
|
|
|
|
|
case WRITE_ADD_CELL:
|
|
|
|
WriteCell = AddCell; break;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( x0 == x1 ) // Vertical.
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( y1 < y0 )
|
|
|
|
EXCHG( y0, y1 );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
dy = y0 / Board.m_GridRouting;
|
|
|
|
lim = y1 / Board.m_GridRouting;
|
|
|
|
dx = x0 / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Clipping limits of board. */
|
|
|
|
if( ( dx < 0 ) || ( dx >= Ncols ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( dy < 0 )
|
|
|
|
dy = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( lim >= Nrows )
|
|
|
|
lim = Nrows - 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; dy <= lim; dy++ )
|
|
|
|
{
|
|
|
|
OP_CELL( layer, dy, dx );
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( y0 == y1 ) // Horizontal
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( x1 < x0 )
|
|
|
|
EXCHG( x0, x1 );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
dx = x0 / Board.m_GridRouting;
|
|
|
|
lim = x1 / Board.m_GridRouting;
|
|
|
|
dy = y0 / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Clipping limits of board. */
|
|
|
|
if( ( dy < 0 ) || ( dy >= Nrows ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( dx < 0 )
|
|
|
|
dx = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( lim >= Ncols )
|
|
|
|
lim = Ncols - 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; dx <= lim; dx++ )
|
|
|
|
{
|
|
|
|
OP_CELL( layer, dy, dx );
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Here is some perspective: using the algorithm LUCAS. */
|
|
|
|
if( abs( x1 - x0 ) >= abs( y1 - y0 ) ) /* segment slightly inclined/ */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( x1 < x0 )
|
|
|
|
{
|
|
|
|
EXCHG( x1, x0 ); EXCHG( y1, y0 );
|
|
|
|
}
|
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
dx = x0 / Board.m_GridRouting;
|
|
|
|
lim = x1 / Board.m_GridRouting;
|
|
|
|
dy = y0 / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
inc = 1;
|
|
|
|
|
|
|
|
if( y1 < y0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
inc = -1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
il = lim - dx; cumul = il / 2;
|
2011-03-09 20:09:11 +00:00
|
|
|
delta = abs( y1 - y0 ) / Board.m_GridRouting;
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; dx <= lim; )
|
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < Ncols ) && ( dy < Nrows ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
OP_CELL( layer, dy, dx );
|
|
|
|
}
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
dx++;
|
|
|
|
cumul += delta;
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( cumul > il )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
cumul -= il;
|
|
|
|
dy += inc;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( y1 < y0 )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
EXCHG( x1, x0 );
|
|
|
|
EXCHG( y1, y0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
dy = y0 / Board.m_GridRouting;
|
|
|
|
lim = y1 / Board.m_GridRouting;
|
|
|
|
dx = x0 / Board.m_GridRouting;
|
2009-11-14 22:15:22 +00:00
|
|
|
inc = 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( x1 < x0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
inc = -1;
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
il = lim - dy; cumul = il / 2;
|
2011-03-09 20:09:11 +00:00
|
|
|
delta = abs( x1 - x0 ) / Board.m_GridRouting;
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; dy <= lim; )
|
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < Ncols ) && ( dy < Nrows ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
OP_CELL( layer, dy, dx );
|
|
|
|
}
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
dy++;
|
|
|
|
cumul += delta;
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( cumul > il )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
cumul -= il;
|
|
|
|
dx += inc;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
|
2011-09-20 13:57:40 +00:00
|
|
|
int aLayerMask, int color, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
int row, col;
|
|
|
|
int row_min, row_max, col_min, col_max;
|
|
|
|
int trace = 0;
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
void (* WriteCell)( int, int, int, MATRIX_CELL );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] )
|
2009-11-14 22:15:22 +00:00
|
|
|
trace = 1; /* Trace on BOTTOM */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] ) && Nb_Sides )
|
2009-11-14 22:15:22 +00:00
|
|
|
trace |= 2; /* Trace on TOP */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( trace == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
switch( op_logic )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case WRITE_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = SetCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_OR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = OrCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_XOR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = XorCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_AND_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AndCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_ADD_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AddCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
ux0 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy0 -= Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
ux1 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy1 -= Pcb->m_BoundaryBox.m_Pos.y;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculating limits coord cells belonging to the rectangle. */
|
2011-03-09 20:09:11 +00:00
|
|
|
row_max = uy1 / Board.m_GridRouting;
|
|
|
|
col_max = ux1 / Board.m_GridRouting;
|
|
|
|
row_min = uy0 / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
if( uy0 > row_min * Board.m_GridRouting )
|
2007-08-23 04:28:46 +00:00
|
|
|
row_min++;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
col_min = ux0 / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
if( ux0 > col_min * Board.m_GridRouting )
|
2007-08-23 04:28:46 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( row_max >= ( Nrows - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
row_max = Nrows - 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( col_max >= ( Ncols - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
|
|
|
if( trace & 1 )
|
|
|
|
WriteCell( row, col, BOTTOM, color );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( trace & 2 )
|
|
|
|
WriteCell( row, col, TOP, color );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1,
|
2011-09-20 13:57:40 +00:00
|
|
|
int angle, int aLayerMask, int color, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
int row, col;
|
2009-11-14 22:15:22 +00:00
|
|
|
int cx, cy; /* Center of rectangle */
|
2011-03-09 14:30:39 +00:00
|
|
|
int radius; /* Radius of the circle */
|
2007-08-23 04:28:46 +00:00
|
|
|
int row_min, row_max, col_min, col_max;
|
|
|
|
int rotrow, rotcol;
|
|
|
|
int trace = 0;
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
void (* WriteCell)( int, int, int, MATRIX_CELL );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] )
|
2009-11-14 22:15:22 +00:00
|
|
|
trace = 1; /* Trace on BOTTOM */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] )
|
2011-09-20 13:57:40 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Nb_Sides )
|
2009-11-14 22:15:22 +00:00
|
|
|
trace |= 2; /* Trace on TOP */
|
2011-09-20 13:57:40 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( trace == 0 )
|
|
|
|
return;
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
switch( op_logic )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case WRITE_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = SetCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_OR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = OrCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_XOR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = XorCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_AND_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AndCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_ADD_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AddCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
ux0 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy0 -= Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
ux1 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy1 -= Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
|
|
|
|
cx = (ux0 + ux1) / 2;
|
|
|
|
cy = (uy0 + uy1) / 2;
|
2011-03-09 14:30:39 +00:00
|
|
|
radius = (int) sqrt( (double) ( cx - ux0 ) * ( cx - ux0 )
|
2009-11-14 22:15:22 +00:00
|
|
|
+ (double) ( cy - uy0 ) * ( cy - uy0 ) );
|
|
|
|
|
|
|
|
/* Calculating coordinate limits belonging to the rectangle. */
|
2011-03-09 20:09:11 +00:00
|
|
|
row_max = ( cy + radius ) / Board.m_GridRouting;
|
|
|
|
col_max = ( cx + radius ) / Board.m_GridRouting;
|
|
|
|
row_min = ( cy - radius ) / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
if( uy0 > row_min * Board.m_GridRouting )
|
2007-08-23 04:28:46 +00:00
|
|
|
row_min++;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
col_min = ( cx - radius ) / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
if( ux0 > col_min * Board.m_GridRouting )
|
2007-08-23 04:28:46 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( row_max >= ( Nrows - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
row_max = Nrows - 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( col_max >= ( Ncols - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
rotrow = row * Board.m_GridRouting;
|
|
|
|
rotcol = col * Board.m_GridRouting;
|
2007-08-23 04:28:46 +00:00
|
|
|
RotatePoint( &rotcol, &rotrow, cx, cy, -angle );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( rotrow <= uy0 )
|
|
|
|
continue;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( rotrow >= uy1 )
|
|
|
|
continue;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( rotcol <= ux0 )
|
|
|
|
continue;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( rotcol >= ux1 )
|
|
|
|
continue;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( trace & 1 )
|
|
|
|
WriteCell( row, col, BOTTOM, color );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( trace & 2 )
|
|
|
|
WriteCell( row, col, TOP, color );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
/* Fills all cells inside a segment
|
|
|
|
* half-width lg, org ux, ux end y0, y1
|
|
|
|
* is set to color.
|
|
|
|
* coordinates are in PCB units (0.1 mil) are relative to the Board
|
2009-11-14 22:15:22 +00:00
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
|
2011-09-20 13:57:40 +00:00
|
|
|
int color, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
int row, col;
|
|
|
|
int inc;
|
|
|
|
int row_max, col_max, row_min, col_min;
|
|
|
|
int demi_pas;
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
void (* WriteCell)( int, int, int, MATRIX_CELL );
|
2007-08-23 04:28:46 +00:00
|
|
|
int angle;
|
|
|
|
int cx, cy, dx, dy;
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
switch( op_logic )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case WRITE_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = SetCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_OR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = OrCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_XOR_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = XorCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_AND_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AndCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
case WRITE_ADD_CELL:
|
2009-11-14 22:15:22 +00:00
|
|
|
WriteCell = AddCell;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Make coordinate ux1 tj > ux0 to simplify calculations */
|
2007-08-23 04:28:46 +00:00
|
|
|
if( ux1 < ux0 )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
EXCHG( ux1, ux0 );
|
|
|
|
EXCHG( uy1, uy0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Calculating the incrementing the Y axis */
|
|
|
|
inc = 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( uy1 < uy0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
inc = -1;
|
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
demi_pas = Board.m_GridRouting / 2;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
col_min = ( ux0 - lg ) / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
col_max = ( ux1 + lg + demi_pas ) / Board.m_GridRouting;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( col_max > ( Ncols - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
|
|
|
if( inc > 0 )
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
row_min = ( uy0 - lg ) / Board.m_GridRouting;
|
|
|
|
row_max = ( uy1 + lg + demi_pas ) / Board.m_GridRouting;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
row_min = ( uy1 - lg ) / Board.m_GridRouting;
|
|
|
|
row_max = ( uy0 + lg + demi_pas ) / Board.m_GridRouting;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( row_min > ( Nrows - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
row_min = Nrows - 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( row_max < 0 )
|
|
|
|
row_max = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( row_max > ( Nrows - 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
row_max = Nrows - 1;
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
dx = ux1 - ux0;
|
|
|
|
dy = uy1 - uy0;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( dx )
|
2011-09-20 13:57:40 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
2011-09-20 13:57:40 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
else
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
angle = 900;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( dy < 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
angle = -900;
|
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
RotatePoint( &dx, &dy, angle ); /* dx = length, dy = 0 */
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
|
|
|
int cxr;
|
2011-03-09 20:09:11 +00:00
|
|
|
cxr = ( col * Board.m_GridRouting ) - ux0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
for( row = row_min; row <= row_max; row++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-03-09 20:09:11 +00:00
|
|
|
cy = (row * Board.m_GridRouting) - uy0;
|
2007-08-23 04:28:46 +00:00
|
|
|
cx = cxr;
|
|
|
|
RotatePoint( &cx, &cy, angle );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( abs( cy ) > lg )
|
2009-11-14 22:15:22 +00:00
|
|
|
continue; /* The point is too far on the Y axis. */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* This point a test is close to the segment: the position
|
|
|
|
* along the X axis must be tested.
|
|
|
|
*/
|
|
|
|
if( ( cx >= 0 ) && ( cx <= dx ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
OP_CELL( layer, row, col );
|
|
|
|
continue;
|
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Examination of extremities are rounded. */
|
|
|
|
if( ( cx < 0 ) && ( cx >= -lg ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
if( ( ( cx * cx ) + ( cy * cy ) ) <= ( lg * lg ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
OP_CELL( layer, row, col );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( ( cx > dx ) && ( cx <= ( dx + lg ) ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
if( ( ( ( cx - dx ) * ( cx - dx ) ) + ( cy * cy ) ) <= ( lg * lg ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
OP_CELL( layer, row, col );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
/* Fills all cells BOARD contained in the circle
|
|
|
|
* half-width lg center ux, ux through y0, y1 is set to color.
|
|
|
|
* coord in PCB units (0.1 million) relating to the origin
|
|
|
|
* pt_pcb-> m_PcbBox.m_Xmin, Y's board.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-09-20 13:57:40 +00:00
|
|
|
void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
|
|
|
|
int color, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-09 14:30:39 +00:00
|
|
|
int radius, nb_segm;
|
2009-11-14 22:15:22 +00:00
|
|
|
int x0, y0, // Starting point of the current segment trace.
|
|
|
|
x1, y1; // End point.
|
2007-08-23 04:28:46 +00:00
|
|
|
int ii;
|
|
|
|
int angle;
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
x0 = x1 = radius;
|
2009-11-14 22:15:22 +00:00
|
|
|
y0 = y1 = 0;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( lg < 1 )
|
|
|
|
lg = 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
nb_segm = ( 2 * radius ) / lg;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( nb_segm < 5 )
|
|
|
|
nb_segm = 5;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( nb_segm > 100 )
|
|
|
|
nb_segm = 100;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ii = 1; ii < nb_segm; ii++ )
|
|
|
|
{
|
|
|
|
angle = (3600 * ii) / nb_segm;
|
2011-09-20 13:57:40 +00:00
|
|
|
x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) );
|
|
|
|
y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) );
|
|
|
|
DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
|
2009-11-14 22:15:22 +00:00
|
|
|
x0 = x1;
|
|
|
|
y0 = y1;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
DrawSegmentQcq( x1 + ux0, y1 + uy0, ux0 + radius, uy0, lg, layer, color, op_logic );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
/* Fills all BOARD cells contained in the arc of "L" angle half-width lg
|
|
|
|
* ux center, starting in ux y0, y1 is set to color. Coordinates are in
|
|
|
|
* PCB units (0.1 mil) relating to the origin pt_pcb-> Pcb_oX, Y's board.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-14 22:15:22 +00:00
|
|
|
void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
|
2011-09-20 13:57:40 +00:00
|
|
|
int layer, int color, int op_logic )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-09 14:30:39 +00:00
|
|
|
int radius, nb_segm;
|
2009-11-14 22:15:22 +00:00
|
|
|
int x0, y0, // Starting point of the current segment trace
|
|
|
|
x1, y1; // End point
|
2007-08-23 04:28:46 +00:00
|
|
|
int ii;
|
|
|
|
int angle, StAngle;
|
|
|
|
|
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
x0 = ux1 - ux0;
|
|
|
|
y0 = uy1 - uy0;
|
2007-08-23 04:28:46 +00:00
|
|
|
StAngle = ArcTangente( uy1 - uy0, ux1 - ux0 );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( lg < 1 )
|
|
|
|
lg = 1;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-03-09 14:30:39 +00:00
|
|
|
nb_segm = ( 2 * radius ) / lg;
|
2007-08-23 04:28:46 +00:00
|
|
|
nb_segm = ( nb_segm * abs( ArcAngle ) ) / 3600;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( nb_segm < 5 )
|
|
|
|
nb_segm = 5;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( nb_segm > 100 )
|
|
|
|
nb_segm = 100;
|
|
|
|
|
|
|
|
for( ii = 1; ii <= nb_segm; ii++ )
|
|
|
|
{
|
2009-11-14 22:15:22 +00:00
|
|
|
angle = ( ArcAngle * ii ) / nb_segm;
|
2007-08-23 04:28:46 +00:00
|
|
|
angle += StAngle;
|
|
|
|
|
|
|
|
while( angle >= 3600 )
|
|
|
|
angle -= 3600;
|
|
|
|
|
|
|
|
while( angle < 0 )
|
|
|
|
angle += 3600;
|
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) );
|
|
|
|
y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) );
|
|
|
|
DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
|
2009-11-14 22:15:22 +00:00
|
|
|
x0 = x1;
|
|
|
|
y0 = y1;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|