From 0028c054849ada3a122e6c04ef843add5679ea44 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 17 Jun 2012 18:06:12 +0200 Subject: [PATCH] Pcbnew: fix issues in kicad nanometer in zone ediition and detection. autoroute functions: code cleaning --- pcbnew/autorouter/autoplac.cpp | 6 +- pcbnew/autorouter/autorout.h | 18 ++- pcbnew/autorouter/graphpcb.cpp | 50 ++++---- pcbnew/autorouter/routing_matrix.cpp | 18 +-- pcbnew/autorouter/solve.cpp | 15 ++- pcbnew/autorouter/work.cpp | 160 ++++++++++++------------- pcbnew/class_zone.cpp | 45 ++++--- pcbnew/dialogs/dialog_copper_zones.cpp | 4 +- pcbnew/legacy_plugin.cpp | 4 +- pcbnew/onleftclick.cpp | 7 +- 10 files changed, 164 insertions(+), 163 deletions(-) diff --git a/pcbnew/autorouter/autoplac.cpp b/pcbnew/autorouter/autoplac.cpp index a09b316ed1..f943e8116e 100644 --- a/pcbnew/autorouter/autoplac.cpp +++ b/pcbnew/autorouter/autoplac.cpp @@ -481,7 +481,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard() TmpSegm.SetShape( DrawSegm->GetShape() ); TmpSegm.m_Param = DrawSegm->GetAngle(); - TraceSegmentPcb( GetBoard(), &TmpSegm, HOLE | CELL_is_EDGE, + TraceSegmentPcb( &TmpSegm, HOLE | CELL_is_EDGE, RoutingMatrix.m_GridRouting, WRITE_CELL ); break; @@ -556,7 +556,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) if( Module->GetLayer() == LAYER_N_BACK ) layerMask = LAYER_BACK; - TraceFilledRectangle( GetBoard(), ox, oy, fx, fy, layerMask, + TraceFilledRectangle( ox, oy, fx, fy, layerMask, CELL_is_MODULE, WRITE_OR_CELL ); int trackWidth = GetBoard()->m_NetClasses.GetDefault()->GetTrackWidth(); @@ -567,7 +567,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) 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. */ diff --git a/pcbnew/autorouter/autorout.h b/pcbnew/autorouter/autorout.h index 2722e2f65c..c6c01f431d 100644 --- a/pcbnew/autorouter/autorout.h +++ b/pcbnew/autorouter/autorout.h @@ -112,6 +112,16 @@ public: (*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 * calculates the number of rows and columns of dimensions of \a aPcb for routing and @@ -176,10 +186,10 @@ class TRACK; * margin: add a value to the radius or half the score pad * 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. */ -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 * 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 * masque_layer = mask layers; * 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); /* 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 ); /* QUEUE.CPP */ diff --git a/pcbnew/autorouter/graphpcb.cpp b/pcbnew/autorouter/graphpcb.cpp index 3e39e5a2c6..77d137ab55 100644 --- a/pcbnew/autorouter/graphpcb.cpp +++ b/pcbnew/autorouter/graphpcb.cpp @@ -57,8 +57,7 @@ static void DrawSegmentQcq( int ux0, int uy0, int lg, int layer, int color, int op_logic ); -static void TraceFilledCircle( BOARD* aPcb, - int cx, int cy, int radius, +static void TraceFilledCircle( int cx, int cy, int radius, int aLayerMask, int color, int op_logic ); @@ -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; wxPoint shape_pos = aPad->ReturnShapePos(); @@ -95,7 +94,7 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic ) 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 ); return; } @@ -118,13 +117,13 @@ void PlacePad( BOARD* aPcb, D_PAD* aPad, int color, int marge, int op_logic ) 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, aPad->GetLayerMask(), color, op_logic ); } 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, (int) aPad->GetOrientation(), aPad->GetLayerMask(), color, 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 * op_logic: type of writing in the cell (WRITE, OR) */ -void TraceFilledCircle( BOARD* aPcb, - int cx, int cy, int radius, +void TraceFilledCircle( int cx, int cy, int radius, int aLayerMask, int color, int op_logic ) @@ -166,8 +164,8 @@ void TraceFilledCircle( BOARD* aPcb, RoutingMatrix.SetCellOperation( op_logic ); - cx -= aPcb->GetBoundingBox().GetX(); - cy -= aPcb->GetBoundingBox().GetY(); + cx -= RoutingMatrix.GetBrdCoordOrigin().x; + cy -= RoutingMatrix.GetBrdCoordOrigin().y; distmin = radius; @@ -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 ux0, uy0, ux1, uy1; @@ -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; // Calculate the bounding rectangle of the segment (if H, V or Via) - ux0 = pt_segm->m_Start.x - aPcb->GetBoundingBox().GetX(); - uy0 = pt_segm->m_Start.y - aPcb->GetBoundingBox().GetY(); - ux1 = pt_segm->m_End.x - aPcb->GetBoundingBox().GetX(); - uy1 = pt_segm->m_End.y - aPcb->GetBoundingBox().GetY(); + ux0 = pt_segm->m_Start.x - RoutingMatrix.GetBrdCoordOrigin().x; + uy0 = pt_segm->m_Start.y - RoutingMatrix.GetBrdCoordOrigin().y; + ux1 = pt_segm->m_End.x - RoutingMatrix.GetBrdCoordOrigin().x; + uy1 = pt_segm->m_End.y - RoutingMatrix.GetBrdCoordOrigin().y; // Test if VIA (filled circle was drawn) if( pt_segm->Type() == PCB_VIA_T ) @@ -292,7 +290,7 @@ void TraceSegmentPcb( BOARD* aPcb, TRACK* pt_segm, int color, int marge, int op_ mask_layer = -1; 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 ); return; } @@ -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 row, col; @@ -485,10 +483,10 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, RoutingMatrix.SetCellOperation( op_logic ); - ux0 -= aPcb->GetBoundingBox().GetX(); - uy0 -= aPcb->GetBoundingBox().GetY(); - ux1 -= aPcb->GetBoundingBox().GetX(); - uy1 -= aPcb->GetBoundingBox().GetY(); + ux0 -= RoutingMatrix.GetBrdCoordOrigin().x; + uy0 -= RoutingMatrix.GetBrdCoordOrigin().y; + ux1 -= RoutingMatrix.GetBrdCoordOrigin().x; + uy1 -= RoutingMatrix.GetBrdCoordOrigin().y; // Calculating limits coord cells belonging to the rectangle. row_max = uy1 / RoutingMatrix.m_GridRouting; @@ -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 row, col; @@ -553,10 +551,10 @@ void TraceFilledRectangle( BOARD* aPcb, int ux0, int uy0, int ux1, int uy1, RoutingMatrix.SetCellOperation( op_logic ); - ux0 -= aPcb->GetBoundingBox().GetX(); - uy0 -= aPcb->GetBoundingBox().GetY(); - ux1 -= aPcb->GetBoundingBox().GetX(); - uy1 -= aPcb->GetBoundingBox().GetY(); + ux0 -= RoutingMatrix.GetBrdCoordOrigin().x; + uy0 -= RoutingMatrix.GetBrdCoordOrigin().y; + ux1 -= RoutingMatrix.GetBrdCoordOrigin().x; + uy1 -= RoutingMatrix.GetBrdCoordOrigin().y; cx = (ux0 + ux1) / 2; cy = (uy0 + uy1) / 2; diff --git a/pcbnew/autorouter/routing_matrix.cpp b/pcbnew/autorouter/routing_matrix.cpp index fc4d5490ff..e48c35ab37 100644 --- a/pcbnew/autorouter/routing_matrix.cpp +++ b/pcbnew/autorouter/routing_matrix.cpp @@ -211,10 +211,10 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) 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 @@ -243,8 +243,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) tmpSegm.m_Param = edge->GetAngle(); tmpSegm.SetNet( -1 ); - TraceSegmentPcb( aPcb, &tmpSegm, HOLE, marge, WRITE_CELL ); - TraceSegmentPcb( aPcb, &tmpSegm, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); + TraceSegmentPcb( &tmpSegm, HOLE, marge, WRITE_CELL ); + TraceSegmentPcb( &tmpSegm, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } break; @@ -280,7 +280,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) tmpSegm.m_Param = DrawSegm->GetAngle(); tmpSegm.SetNet( -1 ); - TraceSegmentPcb( aPcb, &tmpSegm, type_cell, marge, WRITE_CELL ); + TraceSegmentPcb( &tmpSegm, type_cell, marge, WRITE_CELL ); } break; @@ -310,11 +310,11 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) 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), 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, (int) (PtText->m_Orient), layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL ); @@ -332,8 +332,8 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) if( net_code == track->GetNet() ) continue; - TraceSegmentPcb( aPcb, track, HOLE, marge, WRITE_CELL ); - TraceSegmentPcb( aPcb, track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); + TraceSegmentPcb( track, HOLE, marge, WRITE_CELL ); + TraceSegmentPcb( track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } } diff --git a/pcbnew/autorouter/solve.cpp b/pcbnew/autorouter/solve.cpp index ebf7972140..8ef2af3e7d 100644 --- a/pcbnew/autorouter/solve.cpp +++ b/pcbnew/autorouter/solve.cpp @@ -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. */ pcbframe->SetStatusText( wxT( "Gen Cells" ) ); - PlacePad( pcbframe->GetBoard(), 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_PadStart, 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) */ @@ -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 ) ) { - 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, } end_of_route: - PlacePad( pcbframe->GetBoard(), 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_PadStart, ~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"), OpenNodes, ClosNodes, MoveNodes ); @@ -1310,9 +1310,8 @@ static void AddNewTrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) /* Out the new track on the matrix board */ for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() ) { - TraceSegmentPcb( pcbframe->GetBoard(), track, HOLE, marge, WRITE_CELL ); - TraceSegmentPcb( pcbframe->GetBoard(), track, VIA_IMPOSSIBLE, - via_marge, WRITE_OR_CELL ); + TraceSegmentPcb( track, HOLE, marge, WRITE_CELL ); + TraceSegmentPcb( track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } // Insert new segments in real board diff --git a/pcbnew/autorouter/work.cpp b/pcbnew/autorouter/work.cpp index f1e35a889e..0db5dad007 100644 --- a/pcbnew/autorouter/work.cpp +++ b/pcbnew/autorouter/work.cpp @@ -41,36 +41,35 @@ #include -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; - int FromRow; /* source row */ - int FromCol; /* source column */ - int net_code; /* net_code */ - int ToRow; /* target row */ - int ToCol; /* target column */ - RATSNEST_ITEM* pt_rats; /* Corresponding ratsnest */ - int ApxDist; /* approximate distance */ - int Cost; /* cost for sort by length */ - int Priority; /* route priority */ + struct CWORK* m_Next; + int m_FromRow; // source row + int m_FromCol; // source column + int m_ToRow; // target row + int m_ToCol; // target column + RATSNEST_ITEM* m_Ratsnest; // Corresponding ratsnest + int m_NetCode; // m_NetCode + int m_ApxDist; // approximate distance + int m_Cost; // cost for sort by length + int m_Priority; // route priority }; -/* pointers to the first and last item of work to do */ -static CWORK* Head = NULL; -static CWORK* Tail = NULL; -static CWORK* Current = NULL; +// pointers to the first and last item of work to do +static CWORK* Head = NULL; +static CWORK* Tail = NULL; +static CWORK* Current = NULL; - -/* initialize the work list */ +// initialize the work list void InitWork() { CWORK* ptr; while( ( ptr = Head ) != NULL ) { - Head = ptr->Next; + Head = ptr->m_Next; delete ptr; } @@ -78,7 +77,7 @@ void InitWork() } -/* initialize the work list */ +// initialize the work list void ReInitWork() { Current = Head; @@ -92,36 +91,35 @@ void ReInitWork() */ static int GetCost( int r1, int c1, int r2, int c2 ); -int SetWork( int r1, int c1, - int n_c, - int r2, int c2, - RATSNEST_ITEM* pt_ch, int pri ) +int SetWork( int r1, int c1, + int n_c, + int r2, int c2, + RATSNEST_ITEM* pt_ch, int pri ) { CWORK* p; if( ( p = (CWORK*) operator new( sizeof(CWORK), std::nothrow ) ) != NULL ) { - p->FromRow = r1; - p->FromCol = c1; - p->net_code = n_c; - p->ToRow = r2; - p->ToCol = c2; - p->pt_rats = pt_ch; - p->ApxDist = GetApxDist( r1, c1, r2, c2 ); - p->Cost = GetCost( r1, c1, r2, c2 ); - p->Priority = pri; - p->Next = NULL; + p->m_FromRow = r1; + p->m_FromCol = c1; + p->m_NetCode = n_c; + p->m_ToRow = r2; + p->m_ToCol = c2; + p->m_Ratsnest = pt_ch; + p->m_ApxDist = GetApxDist( r1, c1, r2, c2 ); + p->m_Cost = GetCost( r1, c1, r2, c2 ); + p->m_Priority = pri; + p->m_Next = NULL; if( Head ) /* attach at end */ - - Tail->Next = p; + Tail->m_Next = p; else /* first in list */ Head = Current = p; Tail = p; return 1; } - else /* can't get any more memory */ + else /* can't get any more memory */ { return 0; } @@ -129,28 +127,26 @@ int SetWork( int r1, int c1, /* fetch a unit of work from the work list */ -void GetWork( int* r1, - int* c1, - int* n_c, - int* r2, - int* c2, +void GetWork( int* r1, int* c1, + int* n_c, + int* r2, int* c2, RATSNEST_ITEM** pt_ch ) { if( Current ) { - *r1 = Current->FromRow; - *c1 = Current->FromCol; - *n_c = Current->net_code; - *r2 = Current->ToRow; - *c2 = Current->ToCol; - *pt_ch = Current->pt_rats; - Current = Current->Next; + *r1 = Current->m_FromRow; + *c1 = Current->m_FromCol; + *n_c = Current->m_NetCode; + *r2 = Current->m_ToRow; + *c2 = Current->m_ToCol; + *pt_ch = Current->m_Ratsnest; + Current = Current->m_Next; } - else /* none left */ + else /* none left */ { - *r1 = *c1 = *r2 = *c2 = ILLEGAL; - *n_c = 0; - *pt_ch = NULL; + *r1 = *c1 = *r2 = *c2 = ILLEGAL; + *n_c = 0; + *pt_ch = NULL; } } @@ -158,60 +154,60 @@ void GetWork( int* r1, /* order the work items; shortest (low cost) first */ void SortWork() { - CWORK* p; - CWORK* q0; /* put PRIORITY PAD_CONNECTs in q0 */ - CWORK* q1; /* sort other PAD_CONNECTs in q1 */ - CWORK* r; + CWORK* p; + CWORK* q0; /* put PRIORITY PAD_CONNECTs in q0 */ + CWORK* q1; /* sort other PAD_CONNECTs in q1 */ + CWORK* r; 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; } else /* attach at end */ { - while( r->Next ) /* search for end */ - r = r->Next; + while( r->m_Next ) /* search for end */ + 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; } - else /* find proper position in list */ + else /* find proper position in list */ { - while( r->Next && p->Cost >= r->Next->Cost ) - r = r->Next; + while( r->m_Next && p->m_Cost >= r->m_Next->m_Cost ) + r = r->m_Next; - p->Next = r->Next; - r->Next = p; + p->m_Next = r->m_Next; + r->m_Next = p; } } - if( (p = q0) != NULL ) /* any priority PAD_CONNECTs? */ + if( (p = q0) != NULL ) /* any priority PAD_CONNECTs? */ { - while( q0->Next ) - q0 = q0->Next; + while( q0->m_Next ) + q0 = q0->m_Next; - q0->Next = q1; + q0->m_Next = q1; } else p = q1; /* 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() */ static int GetCost( int r1, int c1, int r2, int c2 ) { - int dx, dy, mx, my; - double incl = 1.0; + int dx, dy, mx, my; + double incl = 1.0; - dx = abs( c2 - c1 ); - dy = abs( r2 - r1 ); - mx = dx; - my = dy; + dx = abs( c2 - c1 ); + dy = abs( r2 - r1 ); + mx = dx; + my = dy; if( mx < my ) { diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 140b0b2cfd..be7c1f2a5f 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -485,26 +485,27 @@ bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) 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 ) { m_CornerSelection = -1; // Set to not found // distance (in internal units) to detect a corner in a zone outline. - // @todo use a scaling factor here of actual screen coordinates, so that - // when nanometers come, it still works. - #define CORNER_MIN_DIST 100 + int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS; - int min_dist = CORNER_MIN_DIST + 1; - -#if 0 - // 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 ) +#if HIT_TEST_USE_PIXELS + // If possible, use a fixed number of pixels. + if( GetBoard() && GetBoard()->GetParent() ) { - // Use grid size because it is known - wxRealPoint grid = GetBoard()->m_PcbFrame->GetCanvas()->GetGrid(); - min_dist = KiROUND( MIN( grid.x, grid.y ) ); + double scale = ((PCB_BASE_FRAME*)GetBoard()->GetParent())->GetScreen()->GetScalingFactor(); + min_dist = KiROUND( MIN_DIST_IN_PIXELS / scale); } #endif @@ -536,21 +537,15 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) m_CornerSelection = -1; // Set to not found - // @todo use a scaling factor here of actual screen coordinates, so that - // when nanometers come, it still works. This should be done in screen coordinates - // not internal units. - #define EDGE_MIN_DIST 200 // distance (in internal units) to detect a zone outline - int min_dist = EDGE_MIN_DIST+1; + // distance (in internal units) to detect a zone outline + int min_dist = MIN_DIST_IN_MILS*IU_PER_MILS; - -#if 0 - // 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 ) +#if HIT_TEST_USE_PIXELS + // If possible, use a fixed number of pixels. + if( GetBoard() && GetBoard()->GetParent() ) { - // Use grid size because it is known - wxRealPoint grid = GetBoard()->m_PcbFrame->GetCanvas()->GetGrid(); - min_dist = KiROUND( MIN( grid.x, grid.y ) ); + double scale = ((PCB_BASE_FRAME*)GetBoard()->GetParent())->GetScreen()->GetScalingFactor(); + min_dist = KiROUND( MIN_DIST_IN_PIXELS / scale); } #endif diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index ac4f324cf1..970da8c103 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -370,7 +370,7 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aPromptForErrors, bool aUseExportab // Test if this is a reasonable value for this parameter // 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 ) { 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 txtvalue = m_ZoneMinThicknessCtrl->GetValue(); 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, _( "Minimum width must be larger than 0.001\" / 0.0254 mm." ) ); diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 205341aebd..fafd814aac 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -3856,12 +3856,12 @@ void FPL_CACHE::ReadAndVerifyHeader( LINE_READER* aReader ) if( !strcmp( units, "mm" ) ) { #if defined( USE_PCBNEW_NANOMETRES ) - m_owner->diskToBiu = 1000000.0; + m_owner->diskToBiu = IU_PER_MM; #elif defined(DEBUG) // mm to deci-mils: // 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 THROW_IO_ERROR( _( "May not load millimeter legacy library file into 'Pcbnew compiled for deci-mils'" ) ); diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index 8749239c11..15b8e1f5ea 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -298,7 +298,8 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) */ 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(); bool hit_on_corner = false; @@ -319,7 +320,9 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) m_canvas->SetAutoPanRequest( true ); 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 ); DrawStruct = GetBoard()->m_CurrentZoneContour;