Commit c4c2cd3a authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: fix issue about order of tracks this order was modified when reading...

Pcbnew: fix issue about order of tracks this order was modified when reading and writing a board, even without any change in board.
Fix compil warnings and wx28 compatibility.
code cleaning in autoroute functions.
parents a71857ba 8b210d05
This diff is collapsed.
......@@ -48,9 +48,6 @@
int Nb_Sides; /* Number of layer for autorouting (0 or 1) */
int Nrows = ILLEGAL;
int Ncols = ILLEGAL;
int Ntotal;
int OpenNodes; /* total number of nodes opened */
int ClosNodes; /* total number of nodes closed */
int MoveNodes; /* total number of nodes moved */
......@@ -194,7 +191,7 @@ void PCB_EDIT_FRAME::Autoroute( wxDC* DC, int mode )
PlaceCells( GetBoard(), -1, FORCE_PADS );
/* Construction of the track list for router. */
Build_Work( GetBoard() );
RoutingMatrix.m_RouteCount = Build_Work( GetBoard() );
// DisplayRoutingMatrix( m_canvas, DC );
......@@ -234,7 +231,7 @@ void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
{
int dcell0, dcell1 = 0, color;
int maxi = 600 / Ncols;
int maxi = 600 / RoutingMatrix.m_Ncols;
maxi = ( maxi * 3 ) / 4;
if( !maxi )
......@@ -242,12 +239,12 @@ void DisplayRoutingMatrix( EDA_DRAW_PANEL* panel, wxDC* DC )
GRSetDrawMode( DC, GR_COPY );
for( int col = 0; col < Ncols; col++ )
for( int col = 0; col < RoutingMatrix.m_Ncols; col++ )
{
for( int row = 0; row < Nrows; row++ )
for( int row = 0; row < RoutingMatrix.m_Nrows; row++ )
{
color = 0;
dcell0 = GetCell( row, col, BOTTOM );
dcell0 = RoutingMatrix.GetCell( row, col, BOTTOM );
if( dcell0 & HOLE )
color = GREEN;
......
......@@ -68,11 +68,6 @@ extern int Nb_Sides; /* Number of layers for autorouting (0 or 1) */
#define FORCE_PADS 1 /* Force placement of pads for any Netcode */
/* board dimensions */
extern int Nrows;
extern int Ncols;
extern int Ntotal;
/* search statistics */
extern int OpenNodes; /* total number of nodes opened */
extern int ClosNodes; /* total number of nodes closed */
......@@ -88,26 +83,35 @@ typedef char DIR_CELL;
/**
* class MATRIX_ROUTING_HEAD
* handle the matrix routing that describes the actual board
*/
class MATRIX_ROUTING_HEAD /* header of blocks of MATRIX_CELL */
class MATRIX_ROUTING_HEAD
{
public:
MATRIX_CELL* m_BoardSide[MAX_SIDES_COUNT]; /* ptr to block of memory: 2-sided board */
DIST_CELL* m_DistSide[MAX_SIDES_COUNT]; /* ptr to block of memory: path distance to
* cells */
DIR_CELL* m_DirSide[MAX_SIDES_COUNT]; /* header of blocks of chars:pointers back to
* source */
MATRIX_CELL* m_BoardSide[MAX_SIDES_COUNT]; // the image map of 2 board sides
DIST_CELL* m_DistSide[MAX_SIDES_COUNT]; // the image map of 2 board sides: distance to
// cells
DIR_CELL* m_DirSide[MAX_SIDES_COUNT]; // the image map of 2 board sides: pointers back to
// source
bool m_InitMatrixDone;
int m_Layers;
int m_Layers; // Layer count (1 2 )
int m_GridRouting; // Size of grid for autoplace/autoroute
EDA_RECT m_BrdBox; // Actual board bounding box
int m_Nrows, m_Ncols;
int m_MemSize;
int m_Nrows, m_Ncols; // Matrix size
int m_MemSize; // Memory requirement, just for statistics
int m_RouteCount; // Number of routes
private:
void (MATRIX_ROUTING_HEAD::* m_opWriteCell)( int aRow, int aCol, int aSide, MATRIX_CELL aCell); // a pointeur to the current selected cell op
public:
MATRIX_ROUTING_HEAD();
~MATRIX_ROUTING_HEAD();
void WriteCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell)
{
(*this.*m_opWriteCell)( aRow, aCol, aSide, aCell );
}
/**
* Function ComputeMatrixSize
* calculates the number of rows and columns of dimensions of \a aPcb for routing and
......@@ -127,6 +131,21 @@ public:
int InitRoutingMatrix();
void UnInitRoutingMatrix();
// Initialize WriteCell to make the aLogicOp
void SetCellOperation( int aLogicOp );
// functions to read/write one cell ( point on grid routing matrix:
MATRIX_CELL GetCell( int aRow, int aCol, int aSide);
void SetCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void OrCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void XorCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void AndCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void AddCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
DIST_CELL GetDist( int aRow, int aCol, int aSide );
void SetDist( int aRow, int aCol, int aSide, DIST_CELL );
int GetDir( int aRow, int aCol, int aSide );
void SetDir( int aRow, int aCol, int aSide, int aDir);
};
extern MATRIX_ROUTING_HEAD RoutingMatrix; /* 2-sided board */
......@@ -195,20 +214,9 @@ void SortWork(); /* order the work items; shortest first */
int GetApxDist( int r1, int c1, int r2, int c2 );
int CalcDist(int x,int y,int z ,int side );
/* BOARD.CPP */
/* routing_matrix.cpp */
int Build_Work( BOARD * Pcb );
void PlaceCells( BOARD * Pcb, int net_code, int flag = 0 );
MATRIX_CELL GetCell( int aRow, int aCol, int aSide);
void SetCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void OrCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void XorCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void AndCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
void AddCell( int aRow, int aCol, int aSide, MATRIX_CELL aCell);
DIST_CELL GetDist( int aRow, int aCol, int aSide );
void SetDist( int aRow, int aCol, int aSide, DIST_CELL );
int GetDir( int aRow, int aCol, int aSide );
void SetDir( int aRow, int aCol, int aSide, int aDir);
#endif // AUTOROUT_H
This diff is collapsed.
......@@ -69,14 +69,12 @@ bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb, bool aUseBoardEdgesOnl
aPcb->SetBoundingBox( m_BrdBox );
m_Nrows = Nrows = m_BrdBox.GetHeight() / m_GridRouting;
m_Ncols = Ncols = m_BrdBox.GetWidth() / m_GridRouting;
m_Nrows = m_BrdBox.GetHeight() / m_GridRouting;
m_Ncols = m_BrdBox.GetWidth() / m_GridRouting;
/* get a small margin for memory allocation: */
Ncols += 1;
m_Nrows = Nrows;
Nrows += 1;
m_Ncols = Ncols;
// gives a small margin
m_Ncols += 1;
m_Nrows += 1;
return true;
}
......@@ -103,15 +101,13 @@ int MATRIX_ROUTING_HEAD::InitRoutingMatrix()
{
int ii, kk;
if( Nrows <= 0 || Ncols <= 0 )
if( m_Nrows <= 0 || m_Ncols <= 0 )
return 0;
m_Nrows = Nrows;
m_Ncols = Ncols;
m_InitMatrixDone = true; // we have been called
// give a small margin for memory allocation:
ii = (Nrows + 1) * (Ncols + 1);
ii = (RoutingMatrix.m_Nrows + 1) * (RoutingMatrix.m_Ncols + 1);
for( kk = 0; kk < m_Layers; kk++ )
{
......@@ -354,7 +350,7 @@ int Build_Work( BOARD* Pcb )
EDA_RECT bbbox = Pcb->GetBoundingBox();
InitWork(); /* clear work list */
Ntotal = 0;
int cellCount = 0;
for( unsigned ii = 0; ii < Pcb->GetRatsnestsCount(); ii++ )
{
......@@ -379,7 +375,7 @@ int Build_Work( BOARD* Pcb )
r1 = ( pt_pad->GetPosition().y - bbbox.GetY() + demi_pas ) / RoutingMatrix.m_GridRouting;
if( r1 < 0 || r1 >= Nrows )
if( r1 < 0 || r1 >= RoutingMatrix.m_Nrows )
{
msg.Printf( wxT( "error : row = %d ( padY %d pcbY %d) " ), r1,
pt_pad->GetPosition().y, bbbox.GetY() );
......@@ -389,7 +385,7 @@ int Build_Work( BOARD* Pcb )
c1 = ( pt_pad->GetPosition().x - bbbox.GetX() + demi_pas ) / RoutingMatrix.m_GridRouting;
if( c1 < 0 || c1 >= Ncols )
if( c1 < 0 || c1 >= RoutingMatrix.m_Ncols )
{
msg.Printf( wxT( "error : col = %d ( padX %d pcbX %d) " ), c1,
pt_pad->GetPosition().x, bbbox.GetX() );
......@@ -402,7 +398,7 @@ int Build_Work( BOARD* Pcb )
r2 = ( pt_pad->GetPosition().y - bbbox.GetY()
+ demi_pas ) / RoutingMatrix.m_GridRouting;
if( r2 < 0 || r2 >= Nrows )
if( r2 < 0 || r2 >= RoutingMatrix.m_Nrows )
{
msg.Printf( wxT( "error : row = %d ( padY %d pcbY %d) " ), r2,
pt_pad->GetPosition().y, bbbox.GetY() );
......@@ -412,7 +408,7 @@ int Build_Work( BOARD* Pcb )
c2 = ( pt_pad->GetPosition().x - bbbox.GetX() + demi_pas ) / RoutingMatrix.m_GridRouting;
if( c2 < 0 || c2 >= Ncols )
if( c2 < 0 || c2 >= RoutingMatrix.m_Ncols )
{
msg.Printf( wxT( "error : col = %d ( padX %d pcbX %d) " ), c2,
pt_pad->GetPosition().x, bbbox.GetX() );
......@@ -421,115 +417,143 @@ int Build_Work( BOARD* Pcb )
}
SetWork( r1, c1, current_net_code, r2, c2, pt_ch, 0 );
Ntotal++;
cellCount++;
}
SortWork();
return Ntotal;
return cellCount;
}
// Initialize WriteCell to make the aLogicOp
void MATRIX_ROUTING_HEAD::SetCellOperation( int aLogicOp )
{
switch( aLogicOp )
{
default:
case WRITE_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::SetCell;
break;
case WRITE_OR_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::OrCell;
break;
case WRITE_XOR_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::XorCell;
break;
case WRITE_AND_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::AndCell;
break;
case WRITE_ADD_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::AddCell;
break;
}
}
/* return the value stored in a cell
*/
MATRIX_CELL GetCell( int aRow, int aCol, int aSide )
MATRIX_CELL MATRIX_ROUTING_HEAD::GetCell( int aRow, int aCol, int aSide )
{
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
return p[aRow * Ncols + aCol];
return p[aRow * m_Ncols + aCol];
}
/* basic cell operation : WRITE operation
*/
void SetCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
void MATRIX_ROUTING_HEAD::SetCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * Ncols + aCol] = x;
p[aRow * m_Ncols + aCol] = x;
}
/* basic cell operation : OR operation
*/
void OrCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
void MATRIX_ROUTING_HEAD::OrCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * Ncols + aCol] |= x;
p[aRow * m_Ncols + aCol] |= x;
}
/* basic cell operation : XOR operation
*/
void XorCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
void MATRIX_ROUTING_HEAD::XorCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * Ncols + aCol] ^= x;
p[aRow * m_Ncols + aCol] ^= x;
}
/* basic cell operation : AND operation
*/
void AndCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
void MATRIX_ROUTING_HEAD::AndCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * Ncols + aCol] &= x;
p[aRow * m_Ncols + aCol] &= x;
}
/* basic cell operation : ADD operation
*/
void AddCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
void MATRIX_ROUTING_HEAD::AddCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * Ncols + aCol] += x;
p[aRow * m_Ncols + aCol] += x;
}
/* fetch distance cell */
DIST_CELL GetDist( int aRow, int aCol, int aSide ) /* fetch distance cell */
DIST_CELL MATRIX_ROUTING_HEAD::GetDist( int aRow, int aCol, int aSide ) /* fetch distance cell */
{
DIST_CELL* p;
p = RoutingMatrix.m_DistSide[aSide];
return p[aRow * Ncols + aCol];
return p[aRow * m_Ncols + aCol];
}
/* store distance cell */
void SetDist( int aRow, int aCol, int aSide, DIST_CELL x )
void MATRIX_ROUTING_HEAD::SetDist( int aRow, int aCol, int aSide, DIST_CELL x )
{
DIST_CELL* p;
p = RoutingMatrix.m_DistSide[aSide];
p[aRow * Ncols + aCol] = x;
p[aRow * m_Ncols + aCol] = x;
}
/* fetch direction cell */
int GetDir( int aRow, int aCol, int aSide )
int MATRIX_ROUTING_HEAD::GetDir( int aRow, int aCol, int aSide )
{
DIR_CELL* p;
p = RoutingMatrix.m_DirSide[aSide];
return (int) (p[aRow * Ncols + aCol]);
return (int) (p[aRow * m_Ncols + aCol]);
}
/* store direction cell */
void SetDir( int aRow, int aCol, int aSide, int x )
void MATRIX_ROUTING_HEAD::SetDir( int aRow, int aCol, int aSide, int x )
{
DIR_CELL* p;
p = RoutingMatrix.m_DirSide[aSide];
p[aRow * Ncols + aCol] = (char) x;
p[aRow * m_Ncols + aCol] = (char) x;
}
This diff is collapsed.
......@@ -92,13 +92,10 @@ void ReInitWork()
*/
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 r2,
int c2,
RATSNEST_ITEM* pt_ch,
int pri )
int r2, int c2,
RATSNEST_ITEM* pt_ch, int pri )
{
CWORK* p;
......@@ -226,11 +223,10 @@ void SortWork()
static int GetCost( int r1, int c1, int r2, int c2 )
{
int dx, dy, mx, my;
double incl;
double incl = 1.0;
dx = abs( c2 - c1 );
dy = abs( r2 - r1 );
incl = 1.0;
mx = dx;
my = dy;
......
......@@ -1075,6 +1075,10 @@ void PCB_BASE_FRAME::RecalculateAllTracksNetcode()
*/
static bool SortTracksByNetCode( const TRACK* const & ref, const TRACK* const & compare )
{
// For items having the same Net, keep the order in list
if( ref->GetNet() == compare->GetNet())
return ref->m_Param < compare->m_Param;
return ref->GetNet() < compare->GetNet();
}
......@@ -1082,6 +1086,7 @@ static bool SortTracksByNetCode( const TRACK* const & ref, const TRACK* const &
* Helper function RebuildTrackChain
* rebuilds the track segment linked list in order to have a chain
* sorted by increasing netcodes.
* We try to keep order of track segments in list, when possible
* @param pcb = board to rebuild
*/
static void RebuildTrackChain( BOARD* pcb )
......@@ -1094,8 +1099,19 @@ static void RebuildTrackChain( BOARD* pcb )
std::vector<TRACK*> trackList;
trackList.reserve( item_count );
for( int i = 0; i < item_count; ++i )
// Put track list in a temporary list to sort tracks by netcode
// We try to keep the initial order of track segments in list, when possible
// so we use m_Param (a member variable used for temporary storage)
// to temporary keep trace of the order of segments
// The sort function uses this variable to sort items that
// have the same net code.
// Without this, during sorting, the initial order is sometimes lost
// by the sort algorithm
for( int ii = 0; ii < item_count; ++ii )
{
pcb->m_Track->m_Param = ii;
trackList.push_back( pcb->m_Track.PopFront() );
}
// the list is empty now
wxASSERT( pcb->m_Track == NULL && pcb->m_Track.GetCount()==0 );
......
......@@ -1103,11 +1103,11 @@ PCB_IO::PCB_IO()
BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties )
{
wxFFile file( aFileName, "r" );
wxFFile file( aFileName, wxT("r") );
if( !file.IsOpened() )
{
THROW_IO_ERROR( _( "Unable to read file \"" ) + GetChars( aFileName ) + wxT( "\"" ) );
THROW_IO_ERROR( _( "Unable to read file \"" ) + aFileName + wxT( "\"" ) );
}
PCB_PARSER parser( new FILE_LINE_READER( file.fp(), aFileName ), aAppendToMe );
......
......@@ -620,7 +620,7 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
T token;
wxString name;
wxString type;
bool isVisible;
bool isVisible = true;
int visibleLayers = 0;
int enabledLayers = 0;
std::vector< LAYER > layers;
......@@ -655,7 +655,7 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
Expecting( "hide or )" );
}
layers.push_back( LAYER( name, LAYER::ParseType( type.c_str() ), isVisible ) );
layers.push_back( LAYER( name, LAYER::ParseType( TO_UTF8( type ) ), isVisible ) );
}
int copperLayerCount = 0;
......@@ -701,7 +701,7 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
{
wxString error;
error.Printf( _( "Cannot determine fixed layer list index of layer name \"%s\"" ),
layers[i].m_Name );
GetChars( layers[i].m_Name ) );
THROW_IO_ERROR( error );
}
}
......@@ -1110,7 +1110,7 @@ void PCB_PARSER::parseNETCLASS() throw( IO_ERROR, PARSE_ERROR )
wxString error;
error.Printf( _( "duplicate NETCLASS name '%s' in file %s at line %d, offset %d" ),
nc->GetName().GetData(), CurSource(), CurLineNumber(), CurOffset() );
nc->GetName().GetData(), CurSource().GetData(), CurLineNumber(), CurOffset() );
THROW_IO_ERROR( error );
}
}
......@@ -2268,8 +2268,8 @@ ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR )
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) +
wxT( " as ZONE_CONTAINER." ) );
int hatchStyle;
int hatchPitch;
int hatchStyle = CPolyLine::NO_HATCH; // Fix compil warning
int hatchPitch = 0; // Fix compil warning
wxPoint pt;
T token;
......
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