Commit 0028c054 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: fix issues in kicad nanometer in zone ediition and detection.

autoroute functions: code cleaning
parent 8c72db66
...@@ -481,7 +481,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard() ...@@ -481,7 +481,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard()
TmpSegm.SetShape( DrawSegm->GetShape() ); TmpSegm.SetShape( DrawSegm->GetShape() );
TmpSegm.m_Param = DrawSegm->GetAngle(); TmpSegm.m_Param = DrawSegm->GetAngle();
TraceSegmentPcb( GetBoard(), &TmpSegm, HOLE | CELL_is_EDGE, TraceSegmentPcb( &TmpSegm, HOLE | CELL_is_EDGE,
RoutingMatrix.m_GridRouting, WRITE_CELL ); RoutingMatrix.m_GridRouting, WRITE_CELL );
break; break;
...@@ -556,7 +556,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) ...@@ -556,7 +556,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module )
if( Module->GetLayer() == LAYER_N_BACK ) if( Module->GetLayer() == LAYER_N_BACK )
layerMask = LAYER_BACK; layerMask = LAYER_BACK;
TraceFilledRectangle( GetBoard(), ox, oy, fx, fy, layerMask, TraceFilledRectangle( ox, oy, fx, fy, layerMask,
CELL_is_MODULE, WRITE_OR_CELL ); CELL_is_MODULE, WRITE_OR_CELL );
int trackWidth = GetBoard()->m_NetClasses.GetDefault()->GetTrackWidth(); int trackWidth = GetBoard()->m_NetClasses.GetDefault()->GetTrackWidth();
...@@ -567,7 +567,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) ...@@ -567,7 +567,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module )
for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() ) for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() )
{ {
::PlacePad( GetBoard(), Pad, CELL_is_MODULE, marge, WRITE_OR_CELL ); ::PlacePad( Pad, CELL_is_MODULE, marge, WRITE_OR_CELL );
} }
/* Trace clearance. */ /* Trace clearance. */
......
...@@ -112,6 +112,16 @@ public: ...@@ -112,6 +112,16 @@ public:
(*this.*m_opWriteCell)( aRow, aCol, aSide, aCell ); (*this.*m_opWriteCell)( aRow, aCol, aSide, aCell );
} }
/**
* function GetBrdCoordOrigin
* @returns the board coordinate corresponding to the
* routing matrix origin ( board coordinate offset )
*/
wxPoint GetBrdCoordOrigin()
{
return m_BrdBox.GetOrigin();
}
/** /**
* Function ComputeMatrixSize * Function ComputeMatrixSize
* calculates the number of rows and columns of dimensions of \a aPcb for routing and * calculates the number of rows and columns of dimensions of \a aPcb for routing and
...@@ -176,10 +186,10 @@ class TRACK; ...@@ -176,10 +186,10 @@ class TRACK;
* margin: add a value to the radius or half the score pad * margin: add a value to the radius or half the score pad
* op_logic: type of writing in the cell (WRITE, OR) * op_logic: type of writing in the cell (WRITE, OR)
*/ */
void PlacePad( BOARD* Pcb, D_PAD* pt_pad, int type, int marge, int op_logic ); void PlacePad( D_PAD* pt_pad, int type, int marge, int op_logic );
/* Draws a segment of track on the board. */ /* Draws a segment of track on the board. */
void TraceSegmentPcb( BOARD* Pcb, TRACK* pt_segm, int type, int marge, int op_logic ); void TraceSegmentPcb( TRACK* pt_segm, int type, int marge, int op_logic );
/* Uses the color value of all cells included in the board /* Uses the color value of all cells included in the board
* coord of the rectangle ux0, uy0 (top right corner) * coord of the rectangle ux0, uy0 (top right corner)
...@@ -188,12 +198,12 @@ void TraceSegmentPcb( BOARD* Pcb, TRACK* pt_segm, int type, int marge, int op_lo ...@@ -188,12 +198,12 @@ void TraceSegmentPcb( BOARD* Pcb, TRACK* pt_segm, int type, int marge, int op_lo
* masque_layer = mask layers; * masque_layer = mask layers;
* op_logic = WRITE_CELL, WRITE_OR_CELL, WRITE_XOR_CELL, WRITE_AND_CELL * op_logic = WRITE_CELL, WRITE_OR_CELL, WRITE_XOR_CELL, WRITE_AND_CELL
*/ */
void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
int side, int color, int op_logic); int side, int color, int op_logic);
/* Same as above, but the rectangle is inclined angle angle. */ /* Same as above, but the rectangle is inclined angle angle. */
void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
int angle, int masque_layer, int color, int op_logic ); int angle, int masque_layer, int color, int op_logic );
/* QUEUE.CPP */ /* QUEUE.CPP */
......
...@@ -57,8 +57,7 @@ static void DrawSegmentQcq( int ux0, int uy0, ...@@ -57,8 +57,7 @@ static void DrawSegmentQcq( int ux0, int uy0,
int lg, int layer, int color, int lg, int layer, int color,
int op_logic ); int op_logic );
static void TraceFilledCircle( BOARD* aPcb, static void TraceFilledCircle( int cx, int cy, int radius,
int cx, int cy, int radius,
int aLayerMask, int aLayerMask,
int color, int color,
int op_logic ); int op_logic );
...@@ -85,7 +84,7 @@ static void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer, ...@@ -85,7 +84,7 @@ static void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, int layer,
} \ } \
} }
void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic ) void PlacePad( D_PAD* aPad, int color, int marge, int op_logic )
{ {
int dx, dy; int dx, dy;
wxPoint shape_pos = aPad->ReturnShapePos(); wxPoint shape_pos = aPad->ReturnShapePos();
...@@ -95,7 +94,7 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic ) ...@@ -95,7 +94,7 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic )
if( aPad->GetShape() == PAD_CIRCLE ) if( aPad->GetShape() == PAD_CIRCLE )
{ {
TraceFilledCircle( aPcb, shape_pos.x, shape_pos.y, dx, TraceFilledCircle( shape_pos.x, shape_pos.y, dx,
aPad->GetLayerMask(), color, op_logic ); aPad->GetLayerMask(), color, op_logic );
return; return;
} }
...@@ -118,13 +117,13 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic ) ...@@ -118,13 +117,13 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic )
EXCHG( dx, dy ); EXCHG( dx, dy );
} }
TraceFilledRectangle( aPcb, shape_pos.x - dx, shape_pos.y - dy, TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy,
shape_pos.x + dx, shape_pos.y + dy, shape_pos.x + dx, shape_pos.y + dy,
aPad->GetLayerMask(), color, op_logic ); aPad->GetLayerMask(), color, op_logic );
} }
else else
{ {
TraceFilledRectangle( aPcb, shape_pos.x - dx, shape_pos.y - dy, TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy,
shape_pos.x + dx, shape_pos.y + dy, shape_pos.x + dx, shape_pos.y + dy,
(int) aPad->GetOrientation(), (int) aPad->GetOrientation(),
aPad->GetLayerMask(), color, op_logic ); aPad->GetLayerMask(), color, op_logic );
...@@ -140,8 +139,7 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic ) ...@@ -140,8 +139,7 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic )
* color: mask write in cells * color: mask write in cells
* op_logic: type of writing in the cell (WRITE, OR) * op_logic: type of writing in the cell (WRITE, OR)
*/ */
void TraceFilledCircle( BOARD* aPcb, void TraceFilledCircle( int cx, int cy, int radius,
int cx, int cy, int radius,
int aLayerMask, int aLayerMask,
int color, int color,
int op_logic ) int op_logic )
...@@ -166,8 +164,8 @@ void TraceFilledCircle( BOARD* aPcb, ...@@ -166,8 +164,8 @@ void TraceFilledCircle( BOARD* aPcb,
RoutingMatrix.SetCellOperation( op_logic ); RoutingMatrix.SetCellOperation( op_logic );
cx -= aPcb->GetBoundingBox().GetX(); cx -= RoutingMatrix.GetBrdCoordOrigin().x;
cy -= aPcb->GetBoundingBox().GetY(); cy -= RoutingMatrix.GetBrdCoordOrigin().y;
distmin = radius; distmin = radius;
...@@ -259,7 +257,7 @@ void TraceFilledCircle( BOARD* aPcb, ...@@ -259,7 +257,7 @@ void TraceFilledCircle( BOARD* aPcb,
} }
void TraceSegmentPcb( BOARD* aPcb, TRACK* pt_segm, int color, int marge, int op_logic ) void TraceSegmentPcb( TRACK* pt_segm, int color, int marge, int op_logic )
{ {
int half_width; int half_width;
int ux0, uy0, ux1, uy1; int ux0, uy0, ux1, uy1;
...@@ -267,10 +265,10 @@ void TraceSegmentPcb( BOARD* aPcb, TRACK* pt_segm, int color, int marge, int op_ ...@@ -267,10 +265,10 @@ void TraceSegmentPcb( BOARD* aPcb, TRACK* pt_segm, int color, int marge, int op_
half_width = ( pt_segm->m_Width / 2 ) + marge; half_width = ( pt_segm->m_Width / 2 ) + marge;
// Calculate the bounding rectangle of the segment (if H, V or Via) // Calculate the bounding rectangle of the segment (if H, V or Via)
ux0 = pt_segm->m_Start.x - aPcb->GetBoundingBox().GetX(); ux0 = pt_segm->m_Start.x - RoutingMatrix.GetBrdCoordOrigin().x;
uy0 = pt_segm->m_Start.y - aPcb->GetBoundingBox().GetY(); uy0 = pt_segm->m_Start.y - RoutingMatrix.GetBrdCoordOrigin().y;
ux1 = pt_segm->m_End.x - aPcb->GetBoundingBox().GetX(); ux1 = pt_segm->m_End.x - RoutingMatrix.GetBrdCoordOrigin().x;
uy1 = pt_segm->m_End.y - aPcb->GetBoundingBox().GetY(); uy1 = pt_segm->m_End.y - RoutingMatrix.GetBrdCoordOrigin().y;
// Test if VIA (filled circle was drawn) // Test if VIA (filled circle was drawn)
if( pt_segm->Type() == PCB_VIA_T ) if( pt_segm->Type() == PCB_VIA_T )
...@@ -292,7 +290,7 @@ void TraceSegmentPcb( BOARD* aPcb, TRACK* pt_segm, int color, int marge, int op_ ...@@ -292,7 +290,7 @@ void TraceSegmentPcb( BOARD* aPcb, TRACK* pt_segm, int color, int marge, int op_
mask_layer = -1; mask_layer = -1;
if( mask_layer ) if( mask_layer )
TraceFilledCircle( aPcb, pt_segm->m_Start.x, pt_segm->m_Start.y, TraceFilledCircle( pt_segm->m_Start.x, pt_segm->m_Start.y,
half_width, mask_layer, color, op_logic ); half_width, mask_layer, color, op_logic );
return; return;
} }
...@@ -467,7 +465,7 @@ void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color, int op_ ...@@ -467,7 +465,7 @@ void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color, int op_
} }
void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
int aLayerMask, int color, int op_logic ) int aLayerMask, int color, int op_logic )
{ {
int row, col; int row, col;
...@@ -485,10 +483,10 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, ...@@ -485,10 +483,10 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1,
RoutingMatrix.SetCellOperation( op_logic ); RoutingMatrix.SetCellOperation( op_logic );
ux0 -= aPcb->GetBoundingBox().GetX(); ux0 -= RoutingMatrix.GetBrdCoordOrigin().x;
uy0 -= aPcb->GetBoundingBox().GetY(); uy0 -= RoutingMatrix.GetBrdCoordOrigin().y;
ux1 -= aPcb->GetBoundingBox().GetX(); ux1 -= RoutingMatrix.GetBrdCoordOrigin().x;
uy1 -= aPcb->GetBoundingBox().GetY(); uy1 -= RoutingMatrix.GetBrdCoordOrigin().y;
// Calculating limits coord cells belonging to the rectangle. // Calculating limits coord cells belonging to the rectangle.
row_max = uy1 / RoutingMatrix.m_GridRouting; row_max = uy1 / RoutingMatrix.m_GridRouting;
...@@ -529,7 +527,7 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, ...@@ -529,7 +527,7 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1,
} }
void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
int angle, int aLayerMask, int color, int op_logic ) int angle, int aLayerMask, int color, int op_logic )
{ {
int row, col; int row, col;
...@@ -553,10 +551,10 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, ...@@ -553,10 +551,10 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1,
RoutingMatrix.SetCellOperation( op_logic ); RoutingMatrix.SetCellOperation( op_logic );
ux0 -= aPcb->GetBoundingBox().GetX(); ux0 -= RoutingMatrix.GetBrdCoordOrigin().x;
uy0 -= aPcb->GetBoundingBox().GetY(); uy0 -= RoutingMatrix.GetBrdCoordOrigin().y;
ux1 -= aPcb->GetBoundingBox().GetX(); ux1 -= RoutingMatrix.GetBrdCoordOrigin().x;
uy1 -= aPcb->GetBoundingBox().GetY(); uy1 -= RoutingMatrix.GetBrdCoordOrigin().y;
cx = (ux0 + ux1) / 2; cx = (ux0 + ux1) / 2;
cy = (uy0 + uy1) / 2; cy = (uy0 + uy1) / 2;
......
...@@ -211,10 +211,10 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -211,10 +211,10 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
if( net_code != pad->GetNet() || (flag & FORCE_PADS) ) if( net_code != pad->GetNet() || (flag & FORCE_PADS) )
{ {
::PlacePad( aPcb, pad, HOLE, marge, WRITE_CELL ); ::PlacePad( pad, HOLE, marge, WRITE_CELL );
} }
::PlacePad( aPcb, pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); ::PlacePad( pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
} }
// Place outlines of modules on matrix routing, if they are on a copper layer // Place outlines of modules on matrix routing, if they are on a copper layer
...@@ -243,8 +243,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -243,8 +243,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
tmpSegm.m_Param = edge->GetAngle(); tmpSegm.m_Param = edge->GetAngle();
tmpSegm.SetNet( -1 ); tmpSegm.SetNet( -1 );
TraceSegmentPcb( aPcb, &tmpSegm, HOLE, marge, WRITE_CELL ); TraceSegmentPcb( &tmpSegm, HOLE, marge, WRITE_CELL );
TraceSegmentPcb( aPcb, &tmpSegm, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); TraceSegmentPcb( &tmpSegm, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
} }
break; break;
...@@ -280,7 +280,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -280,7 +280,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
tmpSegm.m_Param = DrawSegm->GetAngle(); tmpSegm.m_Param = DrawSegm->GetAngle();
tmpSegm.SetNet( -1 ); tmpSegm.SetNet( -1 );
TraceSegmentPcb( aPcb, &tmpSegm, type_cell, marge, WRITE_CELL ); TraceSegmentPcb( &tmpSegm, type_cell, marge, WRITE_CELL );
} }
break; break;
...@@ -310,11 +310,11 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -310,11 +310,11 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
layerMask = GetLayerMask( PtText->GetLayer() ); layerMask = GetLayerMask( PtText->GetLayer() );
TraceFilledRectangle( aPcb, ux0 - marge, uy0 - marge, ux1 + marge, TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge,
uy1 + marge, (int) (PtText->m_Orient), uy1 + marge, (int) (PtText->m_Orient),
layerMask, HOLE, WRITE_CELL ); layerMask, HOLE, WRITE_CELL );
TraceFilledRectangle( aPcb, ux0 - via_marge, uy0 - via_marge, TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge,
ux1 + via_marge, uy1 + via_marge, ux1 + via_marge, uy1 + via_marge,
(int) (PtText->m_Orient), (int) (PtText->m_Orient),
layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL ); layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL );
...@@ -332,8 +332,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -332,8 +332,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
if( net_code == track->GetNet() ) if( net_code == track->GetNet() )
continue; continue;
TraceSegmentPcb( aPcb, track, HOLE, marge, WRITE_CELL ); TraceSegmentPcb( track, HOLE, marge, WRITE_CELL );
TraceSegmentPcb( aPcb, track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); TraceSegmentPcb( track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
} }
} }
......
...@@ -504,8 +504,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -504,8 +504,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
/* Placing the bit to remove obstacles on 2 pads to a link. */ /* Placing the bit to remove obstacles on 2 pads to a link. */
pcbframe->SetStatusText( wxT( "Gen Cells" ) ); pcbframe->SetStatusText( wxT( "Gen Cells" ) );
PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadStart, CURRENT_PAD, marge, WRITE_OR_CELL ); PlacePad( pt_cur_ch->m_PadStart, CURRENT_PAD, marge, WRITE_OR_CELL );
PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadEnd, CURRENT_PAD, marge, WRITE_OR_CELL ); PlacePad( pt_cur_ch->m_PadEnd, CURRENT_PAD, marge, WRITE_OR_CELL );
/* Regenerates the remaining barriers (which may encroach on the placement bits precedent) /* Regenerates the remaining barriers (which may encroach on the placement bits precedent)
*/ */
...@@ -517,7 +517,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -517,7 +517,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
if( ( pt_cur_ch->m_PadStart != ptr ) && ( pt_cur_ch->m_PadEnd != ptr ) ) if( ( pt_cur_ch->m_PadStart != ptr ) && ( pt_cur_ch->m_PadEnd != ptr ) )
{ {
PlacePad( pcbframe->GetBoard(), ptr, ~CURRENT_PAD, marge, WRITE_AND_CELL ); PlacePad( ptr, ~CURRENT_PAD, marge, WRITE_AND_CELL );
} }
} }
...@@ -811,8 +811,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, ...@@ -811,8 +811,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
} }
end_of_route: end_of_route:
PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadStart, ~CURRENT_PAD, marge, WRITE_AND_CELL ); PlacePad( pt_cur_ch->m_PadStart, ~CURRENT_PAD, marge, WRITE_AND_CELL );
PlacePad( pcbframe->GetBoard(), pt_cur_ch->m_PadEnd, ~CURRENT_PAD, marge, WRITE_AND_CELL ); PlacePad( pt_cur_ch->m_PadEnd, ~CURRENT_PAD, marge, WRITE_AND_CELL );
msg.Printf( wxT( "Activity: Open %d Closed %d Moved %d"), msg.Printf( wxT( "Activity: Open %d Closed %d Moved %d"),
OpenNodes, ClosNodes, MoveNodes ); OpenNodes, ClosNodes, MoveNodes );
...@@ -1310,9 +1310,8 @@ static void AddNewTrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) ...@@ -1310,9 +1310,8 @@ static void AddNewTrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC )
/* Out the new track on the matrix board */ /* Out the new track on the matrix board */
for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() ) for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() )
{ {
TraceSegmentPcb( pcbframe->GetBoard(), track, HOLE, marge, WRITE_CELL ); TraceSegmentPcb( track, HOLE, marge, WRITE_CELL );
TraceSegmentPcb( pcbframe->GetBoard(), track, VIA_IMPOSSIBLE, TraceSegmentPcb( track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
via_marge, WRITE_OR_CELL );
} }
// Insert new segments in real board // Insert new segments in real board
......
...@@ -41,36 +41,35 @@ ...@@ -41,36 +41,35 @@
#include <cell.h> #include <cell.h>
struct CWORK /* a unit of work is a hole-pair to connect */ struct CWORK // a unit of work is a source-target (a ratsnet item) to connect
{ {
struct CWORK* Next; struct CWORK* m_Next;
int FromRow; /* source row */ int m_FromRow; // source row
int FromCol; /* source column */ int m_FromCol; // source column
int net_code; /* net_code */ int m_ToRow; // target row
int ToRow; /* target row */ int m_ToCol; // target column
int ToCol; /* target column */ RATSNEST_ITEM* m_Ratsnest; // Corresponding ratsnest
RATSNEST_ITEM* pt_rats; /* Corresponding ratsnest */ int m_NetCode; // m_NetCode
int ApxDist; /* approximate distance */ int m_ApxDist; // approximate distance
int Cost; /* cost for sort by length */ int m_Cost; // cost for sort by length
int Priority; /* route priority */ int m_Priority; // route priority
}; };
/* pointers to the first and last item of work to do */ // pointers to the first and last item of work to do
static CWORK* Head = NULL; static CWORK* Head = NULL;
static CWORK* Tail = NULL; static CWORK* Tail = NULL;
static CWORK* Current = NULL; static CWORK* Current = NULL;
// initialize the work list
/* initialize the work list */
void InitWork() void InitWork()
{ {
CWORK* ptr; CWORK* ptr;
while( ( ptr = Head ) != NULL ) while( ( ptr = Head ) != NULL )
{ {
Head = ptr->Next; Head = ptr->m_Next;
delete ptr; delete ptr;
} }
...@@ -78,7 +77,7 @@ void InitWork() ...@@ -78,7 +77,7 @@ void InitWork()
} }
/* initialize the work list */ // initialize the work list
void ReInitWork() void ReInitWork()
{ {
Current = Head; Current = Head;
...@@ -92,36 +91,35 @@ void ReInitWork() ...@@ -92,36 +91,35 @@ void ReInitWork()
*/ */
static int GetCost( int r1, int c1, int r2, int c2 ); static int GetCost( int r1, int c1, int r2, int c2 );
int SetWork( int r1, int c1, int SetWork( int r1, int c1,
int n_c, int n_c,
int r2, int c2, int r2, int c2,
RATSNEST_ITEM* pt_ch, int pri ) RATSNEST_ITEM* pt_ch, int pri )
{ {
CWORK* p; CWORK* p;
if( ( p = (CWORK*) operator new( sizeof(CWORK), std::nothrow ) ) != NULL ) if( ( p = (CWORK*) operator new( sizeof(CWORK), std::nothrow ) ) != NULL )
{ {
p->FromRow = r1; p->m_FromRow = r1;
p->FromCol = c1; p->m_FromCol = c1;
p->net_code = n_c; p->m_NetCode = n_c;
p->ToRow = r2; p->m_ToRow = r2;
p->ToCol = c2; p->m_ToCol = c2;
p->pt_rats = pt_ch; p->m_Ratsnest = pt_ch;
p->ApxDist = GetApxDist( r1, c1, r2, c2 ); p->m_ApxDist = GetApxDist( r1, c1, r2, c2 );
p->Cost = GetCost( r1, c1, r2, c2 ); p->m_Cost = GetCost( r1, c1, r2, c2 );
p->Priority = pri; p->m_Priority = pri;
p->Next = NULL; p->m_Next = NULL;
if( Head ) /* attach at end */ if( Head ) /* attach at end */
Tail->m_Next = p;
Tail->Next = p;
else /* first in list */ else /* first in list */
Head = Current = p; Head = Current = p;
Tail = p; Tail = p;
return 1; return 1;
} }
else /* can't get any more memory */ else /* can't get any more memory */
{ {
return 0; return 0;
} }
...@@ -129,28 +127,26 @@ int SetWork( int r1, int c1, ...@@ -129,28 +127,26 @@ int SetWork( int r1, int c1,
/* fetch a unit of work from the work list */ /* fetch a unit of work from the work list */
void GetWork( int* r1, void GetWork( int* r1, int* c1,
int* c1, int* n_c,
int* n_c, int* r2, int* c2,
int* r2,
int* c2,
RATSNEST_ITEM** pt_ch ) RATSNEST_ITEM** pt_ch )
{ {
if( Current ) if( Current )
{ {
*r1 = Current->FromRow; *r1 = Current->m_FromRow;
*c1 = Current->FromCol; *c1 = Current->m_FromCol;
*n_c = Current->net_code; *n_c = Current->m_NetCode;
*r2 = Current->ToRow; *r2 = Current->m_ToRow;
*c2 = Current->ToCol; *c2 = Current->m_ToCol;
*pt_ch = Current->pt_rats; *pt_ch = Current->m_Ratsnest;
Current = Current->Next; Current = Current->m_Next;
} }
else /* none left */ else /* none left */
{ {
*r1 = *c1 = *r2 = *c2 = ILLEGAL; *r1 = *c1 = *r2 = *c2 = ILLEGAL;
*n_c = 0; *n_c = 0;
*pt_ch = NULL; *pt_ch = NULL;
} }
} }
...@@ -158,60 +154,60 @@ void GetWork( int* r1, ...@@ -158,60 +154,60 @@ void GetWork( int* r1,
/* order the work items; shortest (low cost) first */ /* order the work items; shortest (low cost) first */
void SortWork() void SortWork()
{ {
CWORK* p; CWORK* p;
CWORK* q0; /* put PRIORITY PAD_CONNECTs in q0 */ CWORK* q0; /* put PRIORITY PAD_CONNECTs in q0 */
CWORK* q1; /* sort other PAD_CONNECTs in q1 */ CWORK* q1; /* sort other PAD_CONNECTs in q1 */
CWORK* r; CWORK* r;
q0 = q1 = NULL; q0 = q1 = NULL;
while( (p = Head) != NULL ) /* prioritize each work item */ while( (p = Head) != NULL ) /* prioritize each work item */
{ {
Head = Head->Next; Head = Head->m_Next;
if( p->Priority ) /* put at end of priority list */ if( p->m_Priority ) /* put at end of priority list */
{ {
p->Next = NULL; p->m_Next = NULL;
if( (r = q0) == NULL ) /* empty list? */ if( (r = q0) == NULL ) /* empty list? */
{ {
q0 = p; q0 = p;
} }
else /* attach at end */ else /* attach at end */
{ {
while( r->Next ) /* search for end */ while( r->m_Next ) /* search for end */
r = r->Next; r = r->m_Next;
r->Next = p; /* attach */ r->m_Next = p; /* attach */
} }
} }
else if( ( ( r = q1 ) == NULL ) || ( p->Cost < q1->Cost ) ) else if( ( ( r = q1 ) == NULL ) || ( p->m_Cost < q1->m_Cost ) )
{ {
p->Next = q1; p->m_Next = q1;
q1 = p; q1 = p;
} }
else /* find proper position in list */ else /* find proper position in list */
{ {
while( r->Next && p->Cost >= r->Next->Cost ) while( r->m_Next && p->m_Cost >= r->m_Next->m_Cost )
r = r->Next; r = r->m_Next;
p->Next = r->Next; p->m_Next = r->m_Next;
r->Next = p; r->m_Next = p;
} }
} }
if( (p = q0) != NULL ) /* any priority PAD_CONNECTs? */ if( (p = q0) != NULL ) /* any priority PAD_CONNECTs? */
{ {
while( q0->Next ) while( q0->m_Next )
q0 = q0->Next; q0 = q0->m_Next;
q0->Next = q1; q0->m_Next = q1;
} }
else else
p = q1; p = q1;
/* reposition Head and Tail */ /* reposition Head and Tail */
for( Head = Current = Tail = p; Tail && Tail->Next; Tail = Tail->Next ) for( Head = Current = Tail = p; Tail && Tail->m_Next; Tail = Tail->m_Next )
; ;
} }
...@@ -222,13 +218,13 @@ void SortWork() ...@@ -222,13 +218,13 @@ void SortWork()
*/ */
static int GetCost( int r1, int c1, int r2, int c2 ) static int GetCost( int r1, int c1, int r2, int c2 )
{ {
int dx, dy, mx, my; int dx, dy, mx, my;
double incl = 1.0; double incl = 1.0;
dx = abs( c2 - c1 ); dx = abs( c2 - c1 );
dy = abs( r2 - r1 ); dy = abs( r2 - r1 );
mx = dx; mx = dx;
my = dy; my = dy;
if( mx < my ) if( mx < my )
{ {
......
...@@ -485,26 +485,27 @@ bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) ...@@ -485,26 +485,27 @@ bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition )
return false; return false;
} }
// Zones outlines have no thickness, so it Hit Test functions
// we must have a default distance between the test point
// and a corner or a zone edge:
#define MIN_DIST_IN_MILS 10
// if we know the scaling factor, a dist in pixel can be used:
#define HIT_TEST_USE_PIXELS 1 // Set to 0 to used only a fixed default distance
#define MIN_DIST_IN_PIXELS 10
bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
{ {
m_CornerSelection = -1; // Set to not found m_CornerSelection = -1; // Set to not found
// distance (in internal units) to detect a corner in a zone outline. // distance (in internal units) to detect a corner in a zone outline.
// @todo use a scaling factor here of actual screen coordinates, so that int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;
// when nanometers come, it still works.
#define CORNER_MIN_DIST 100
int min_dist = CORNER_MIN_DIST + 1; #if HIT_TEST_USE_PIXELS
// If possible, use a fixed number of pixels.
#if 0 if( GetBoard() && GetBoard()->GetParent() )
// Dick: I don't see this as reasonable. The mouse distance from the zone is
// not a function of the grid, it is a fixed number of pixels, regardless of zoom.
if( GetBoard() && GetBoard()->m_PcbFrame )
{ {
// Use grid size because it is known double scale = ((PCB_BASE_FRAME*)GetBoard()->GetParent())->GetScreen()->GetScalingFactor();
wxRealPoint grid = GetBoard()->m_PcbFrame->GetCanvas()->GetGrid(); min_dist = KiROUND( MIN_DIST_IN_PIXELS / scale);
min_dist = KiROUND( MIN( grid.x, grid.y ) );
} }
#endif #endif
...@@ -536,21 +537,15 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) ...@@ -536,21 +537,15 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
m_CornerSelection = -1; // Set to not found m_CornerSelection = -1; // Set to not found
// @todo use a scaling factor here of actual screen coordinates, so that // distance (in internal units) to detect a zone outline
// when nanometers come, it still works. This should be done in screen coordinates int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS;
// not internal units.
#define EDGE_MIN_DIST 200 // distance (in internal units) to detect a zone outline
int min_dist = EDGE_MIN_DIST+1;
#if 0 #if HIT_TEST_USE_PIXELS
// Dick: I don't see this as reasonable. The mouse distance from the zone is // If possible, use a fixed number of pixels.
// not a function of the grid, it is a fixed number of pixels, regardless of zoom. if( GetBoard() && GetBoard()->GetParent() )
if( GetBoard() && GetBoard()->m_PcbFrame )
{ {
// Use grid size because it is known double scale = ((PCB_BASE_FRAME*)GetBoard()->GetParent())->GetScreen()->GetScalingFactor();
wxRealPoint grid = GetBoard()->m_PcbFrame->GetCanvas()->GetGrid(); min_dist = KiROUND( MIN_DIST_IN_PIXELS / scale);
min_dist = KiROUND( MIN( grid.x, grid.y ) );
} }
#endif #endif
......
...@@ -370,7 +370,7 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab ...@@ -370,7 +370,7 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab
// Test if this is a reasonable value for this parameter // Test if this is a reasonable value for this parameter
// A too large value can hang Pcbnew // A too large value can hang Pcbnew
#define CLEARANCE_MAX_VALUE 5000 // in 1/10000 inch #define CLEARANCE_MAX_VALUE 100*IU_PER_MILS
if( m_settings.m_ZoneClearance > CLEARANCE_MAX_VALUE ) if( m_settings.m_ZoneClearance > CLEARANCE_MAX_VALUE )
{ {
DisplayError( this, _( "Clearance must be smaller than 0.5\" / 12.7 mm." ) ); DisplayError( this, _( "Clearance must be smaller than 0.5\" / 12.7 mm." ) );
...@@ -380,7 +380,7 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab ...@@ -380,7 +380,7 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab
txtvalue = m_ZoneMinThicknessCtrl->GetValue(); txtvalue = m_ZoneMinThicknessCtrl->GetValue();
m_settings.m_ZoneMinThickness = ReturnValueFromString( g_UserUnit, txtvalue ); m_settings.m_ZoneMinThickness = ReturnValueFromString( g_UserUnit, txtvalue );
if( m_settings.m_ZoneMinThickness < 10 ) if( m_settings.m_ZoneMinThickness < (1*IU_PER_MILS) )
{ {
DisplayError( this, DisplayError( this,
_( "Minimum width must be larger than 0.001\" / 0.0254 mm." ) ); _( "Minimum width must be larger than 0.001\" / 0.0254 mm." ) );
......
...@@ -3856,12 +3856,12 @@ void FPL_CACHE::ReadAndVerifyHeader( LINE_READER* aReader ) ...@@ -3856,12 +3856,12 @@ void FPL_CACHE::ReadAndVerifyHeader( LINE_READER* aReader )
if( !strcmp( units, "mm" ) ) if( !strcmp( units, "mm" ) )
{ {
#if defined( USE_PCBNEW_NANOMETRES ) #if defined( USE_PCBNEW_NANOMETRES )
m_owner->diskToBiu = 1000000.0; m_owner->diskToBiu = IU_PER_MM;
#elif defined(DEBUG) #elif defined(DEBUG)
// mm to deci-mils: // mm to deci-mils:
// advanced testing of round tripping only, not supported in non DEBUG build // advanced testing of round tripping only, not supported in non DEBUG build
m_owner->diskToBiu = 10000/25.4; m_owner->diskToBiu = IU_PER_MM;
#else #else
THROW_IO_ERROR( _( "May not load millimeter legacy library file into 'Pcbnew compiled for deci-mils'" ) ); THROW_IO_ERROR( _( "May not load millimeter legacy library file into 'Pcbnew compiled for deci-mils'" ) );
......
...@@ -298,7 +298,8 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -298,7 +298,8 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
*/ */
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) ) if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) )
{ {
// there is no current item, try to find something under mouse #if 0 // Set to 1 to automatically edit a zone found under the mouse
// there is no current item, try to find something under the mouse cursor
DrawStruct = PcbGeneralLocateAndDisplay(); DrawStruct = PcbGeneralLocateAndDisplay();
bool hit_on_corner = false; bool hit_on_corner = false;
...@@ -319,7 +320,9 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -319,7 +320,9 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
Start_Move_Zone_Corner( aDC, zone_cont, zone_cont->m_CornerSelection, false ); Start_Move_Zone_Corner( aDC, zone_cont, zone_cont->m_CornerSelection, false );
} }
else if( Begin_Zone( aDC ) ) else
#endif
if( Begin_Zone( aDC ) )
{ {
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
DrawStruct = GetBoard()->m_CurrentZoneContour; DrawStruct = GetBoard()->m_CurrentZoneContour;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment