Commit 46f106b6 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: fix Bug #1148785 (pcbnew crashes when using only one layer in...

Pcbnew: fix Bug #1148785 (pcbnew crashes when using only one layer in autorouter ) , and a minor bug in dialog cleanup.
parent c1fbc8ef
......@@ -410,7 +410,9 @@ void TracePcbLine( int x0, int y0, int x1, int y1, int layer, int color, int op_
for( ; dx <= lim; )
{
if( ( dx >= 0 ) && ( dy >= 0 ) && ( dx < RoutingMatrix.m_Ncols ) && ( dy < RoutingMatrix.m_Nrows ) )
if( ( dx >= 0 ) && ( dy >= 0 ) &&
( dx < RoutingMatrix.m_Ncols ) &&
( dy < RoutingMatrix.m_Nrows ) )
{
OP_CELL( layer, dy, dx );
}
......@@ -475,7 +477,8 @@ void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
if( ( aLayerMask & GetLayerMask( Route_Layer_BOTTOM ) ) )
trace = 1; // Trace on BOTTOM
if( ( aLayerMask & GetLayerMask( Route_Layer_TOP ) ) && RoutingMatrix.m_RoutingLayersCount > 1 )
if( ( aLayerMask & GetLayerMask( Route_Layer_TOP ) ) &&
RoutingMatrix.m_RoutingLayersCount > 1 )
trace |= 2; // Trace on TOP
if( trace == 0 )
......
......@@ -100,45 +100,47 @@ bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb, bool aUseBoardEdgesOnl
int MATRIX_ROUTING_HEAD::InitRoutingMatrix()
{
int ii, kk;
if( m_Nrows <= 0 || m_Ncols <= 0 )
return 0;
m_InitMatrixDone = true; // we have been called
// give a small margin for memory allocation:
ii = (RoutingMatrix.m_Nrows + 1) * (RoutingMatrix.m_Ncols + 1);
int ii = (RoutingMatrix.m_Nrows + 1) * (RoutingMatrix.m_Ncols + 1);
for( kk = 0; kk < m_RoutingLayersCount; kk++ )
int side = BOTTOM;
for( int jj = 0; jj < m_RoutingLayersCount; jj++ ) // m_RoutingLayersCount = 1 or 2
{
m_BoardSide[kk] = NULL;
m_DistSide[kk] = NULL;
m_DirSide[kk] = NULL;
m_BoardSide[side] = NULL;
m_DistSide[side] = NULL;
m_DirSide[side] = NULL;
/* allocate matrix & initialize everything to empty */
m_BoardSide[kk] = (MATRIX_CELL*) operator new( ii * sizeof(MATRIX_CELL) );
memset( m_BoardSide[kk], 0, ii * sizeof(MATRIX_CELL) );
m_BoardSide[side] = (MATRIX_CELL*) operator new( ii * sizeof(MATRIX_CELL) );
memset( m_BoardSide[side], 0, ii * sizeof(MATRIX_CELL) );
if( m_BoardSide[kk] == NULL )
if( m_BoardSide[side] == NULL )
return -1;
// allocate Distances
m_DistSide[kk] = (DIST_CELL*) operator new( ii * sizeof(DIST_CELL) );
memset( m_DistSide[kk], 0, ii * sizeof(DIST_CELL) );
m_DistSide[side] = (DIST_CELL*) operator new( ii * sizeof(DIST_CELL) );
memset( m_DistSide[side], 0, ii * sizeof(DIST_CELL) );
if( m_DistSide[kk] == NULL )
if( m_DistSide[side] == NULL )
return -1;
// allocate Dir (chars)
m_DirSide[kk] = (char*) operator new( ii );
memset( m_DirSide[kk], 0, ii );
m_DirSide[side] = (char*) operator new( ii );
memset( m_DirSide[side], 0, ii );
if( m_DirSide[kk] == NULL )
if( m_DirSide[side] == NULL )
return -1;
side = TOP;
}
m_MemSize = m_RouteCount * ii * ( sizeof(MATRIX_CELL) + sizeof(DIST_CELL) + sizeof(char) );
m_MemSize = m_RouteCount * ii * ( sizeof(MATRIX_CELL)
+ sizeof(DIST_CELL) + sizeof(char) );
return m_MemSize;
}
......
......@@ -433,13 +433,16 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe,
/* clear direction flags */
i = RoutingMatrix.m_Nrows * RoutingMatrix.m_Ncols * sizeof(DIR_CELL);
memset( RoutingMatrix.m_DirSide[TOP], FROM_NOWHERE, i );
if( two_sides )
memset( RoutingMatrix.m_DirSide[TOP], FROM_NOWHERE, i );
memset( RoutingMatrix.m_DirSide[BOTTOM], FROM_NOWHERE, i );
lastopen = lastclos = lastmove = 0;
/* Set tab_masque[side] for final test of routing. */
tab_mask[TOP] = topLayerMask;
if( two_sides )
tab_mask[TOP] = topLayerMask;
tab_mask[BOTTOM] = bottomLayerMask;
/* Set active layers mask. */
......@@ -1170,11 +1173,11 @@ static void OrCell_Trace( BOARD* pcb, int col, int row,
g_CurrentTrackSegment->SetLayer( 0x0F );
g_CurrentTrackSegment->SetStart(wxPoint( pcb->GetBoundingBox().GetX() +
( RoutingMatrix.m_GridRouting * row ),
( RoutingMatrix.m_GridRouting * row ),
pcb->GetBoundingBox().GetY() +
( RoutingMatrix.m_GridRouting * col )));
g_CurrentTrackSegment->SetEnd( g_CurrentTrackSegment->GetStart() );
g_CurrentTrackSegment->SetWidth( pcb->GetCurrentViaSize() );
g_CurrentTrackSegment->SetShape( pcb->GetDesignSettings().m_CurrentViaType );
......
......@@ -112,21 +112,22 @@ void PCB_EDIT_FRAME::Clean_Pcb( wxDC* DC )
{
DIALOG_CLEANING_OPTIONS dlg( this );
if( dlg.ShowModal() == wxID_OK )
if( dlg.ShowModal() != wxID_OK )
return;
wxBusyCursor( dummy );
TRACKS_CLEANER cleaner( GetBoard() );
cleaner.SetdeleteUnconnectedTracksOpt( dlg.deleteUnconnectedSegm );
cleaner.SetMergeSegmentsOpt( dlg.mergeSegments );
cleaner.SetCleanViasOpt( dlg.cleanVias );
if( cleaner.CleanupBoard() )
{
wxBusyCursor( dummy );
TRACKS_CLEANER cleaner( GetBoard() );
cleaner.SetdeleteUnconnectedTracksOpt( dlg.deleteUnconnectedSegm );
cleaner.SetMergeSegmentsOpt( dlg.mergeSegments );
cleaner.SetCleanViasOpt( dlg.cleanVias );
if( cleaner.CleanupBoard() )
{
// Clear undo and redo lists to avoid inconsistencies between lists
GetScreen()->ClearUndoRedoList();
SetCurItem( NULL );
Compile_Ratsnest( NULL, true );
OnModify();
}
// Clear undo and redo lists to avoid inconsistencies between lists
GetScreen()->ClearUndoRedoList();
SetCurItem( NULL );
Compile_Ratsnest( NULL, true );
OnModify();
}
m_canvas->Refresh( true );
......
......@@ -32,9 +32,9 @@
DIALOG_CLEANING_OPTIONS::DIALOG_CLEANING_OPTIONS( wxWindow* parent ):
DIALOG_CLEANING_OPTIONS_BASE( parent )
{
m_cleanViasOpt->SetValue( cleanVias );
m_mergeSegmOpt->SetValue( mergeSegments );
m_deleteUnconnectedOpt->SetValue( deleteUnconnectedSegm );
m_cleanViasOpt->SetValue( m_cleanVias );
m_mergeSegmOpt->SetValue( m_mergeSegments );
m_deleteUnconnectedOpt->SetValue( m_deleteUnconnectedSegm );
m_sdbSizerOK->SetDefault();
GetSizer()->SetSizeHints(this);
......@@ -42,7 +42,7 @@ DIALOG_CLEANING_OPTIONS::DIALOG_CLEANING_OPTIONS( wxWindow* parent ):
}
// Static members of DIALOG_CLEANING_OPTIONS
bool DIALOG_CLEANING_OPTIONS::cleanVias = true;
bool DIALOG_CLEANING_OPTIONS::mergeSegments = true;
bool DIALOG_CLEANING_OPTIONS::deleteUnconnectedSegm = true;
bool DIALOG_CLEANING_OPTIONS::m_cleanVias = true;
bool DIALOG_CLEANING_OPTIONS::m_mergeSegments = true;
bool DIALOG_CLEANING_OPTIONS::m_deleteUnconnectedSegm = true;
......@@ -11,15 +11,16 @@
class DIALOG_CLEANING_OPTIONS: public DIALOG_CLEANING_OPTIONS_BASE
{
public:
static bool cleanVias;
static bool mergeSegments;
static bool deleteUnconnectedSegm;
static bool m_cleanVias;
static bool m_mergeSegments;
static bool m_deleteUnconnectedSegm;
public:
DIALOG_CLEANING_OPTIONS( wxWindow* parent );
~DIALOG_CLEANING_OPTIONS()
{
GetOpts( );
}
private:
......@@ -33,17 +34,11 @@ private:
EndModal( wxID_OK );
}
void OnCloseWindow( wxCloseEvent& event )
{
GetOpts( );
EndModal( wxID_CANCEL );
}
void GetOpts( )
{
cleanVias = m_cleanViasOpt->GetValue( );
mergeSegments = m_mergeSegmOpt->GetValue( );
deleteUnconnectedSegm = m_deleteUnconnectedOpt->GetValue( );
m_cleanVias = m_cleanViasOpt->GetValue( );
m_mergeSegments = m_mergeSegmOpt->GetValue( );
m_deleteUnconnectedSegm = m_deleteUnconnectedOpt->GetValue( );
}
};
......
......@@ -56,7 +56,6 @@ DIALOG_CLEANING_OPTIONS_BASE::DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wx
this->Centre( wxBOTH );
// Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_CLEANING_OPTIONS_BASE::OnCloseWindow ) );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CLEANING_OPTIONS_BASE::OnCancelClick ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CLEANING_OPTIONS_BASE::OnOKClick ), NULL, this );
}
......@@ -64,7 +63,6 @@ DIALOG_CLEANING_OPTIONS_BASE::DIALOG_CLEANING_OPTIONS_BASE( wxWindow* parent, wx
DIALOG_CLEANING_OPTIONS_BASE::~DIALOG_CLEANING_OPTIONS_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_CLEANING_OPTIONS_BASE::OnCloseWindow ) );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CLEANING_OPTIONS_BASE::OnCancelClick ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_CLEANING_OPTIONS_BASE::OnOKClick ), NULL, this );
......
......@@ -59,7 +59,7 @@
<event name="OnAuiPaneRestore"></event>
<event name="OnAuiRender"></event>
<event name="OnChar"></event>
<event name="OnClose">OnCloseWindow</event>
<event name="OnClose"></event>
<event name="OnEnterWindow"></event>
<event name="OnEraseBackground"></event>
<event name="OnHibernate"></event>
......
......@@ -45,7 +45,6 @@ class DIALOG_CLEANING_OPTIONS_BASE : public DIALOG_SHIM
wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnCloseWindow( wxCloseEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOKClick( wxCommandEvent& event ) { event.Skip(); }
......
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