Clear out old layer data when loading on top of an existing image

Fixes: lp:1747443
* https://bugs.launchpad.net/kicad/+bug/1747443
This commit is contained in:
Jon Evans 2018-02-22 19:31:51 -05:00 committed by jean-pierre charras
parent 1597f31d4b
commit 1ed7d5f816
2 changed files with 19 additions and 9 deletions

View File

@ -163,12 +163,19 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
wxString msg;
int layerId = GetActiveLayer(); // current layer used in GerbView
GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList();
EXCELLON_IMAGE* drill_Layer = (EXCELLON_IMAGE*) images->GetGbrImage( layerId );
auto gerber_layer = images->GetGbrImage( layerId );
auto drill_layer = dynamic_cast<EXCELLON_IMAGE*>( gerber_layer );
if( drill_Layer == NULL )
if( gerber_layer && !drill_layer )
{
drill_Layer = new EXCELLON_IMAGE( layerId );
layerId = images->AddGbrImage( drill_Layer, layerId );
// The active layer contains old gerber data we have to clear
Erase_Current_DrawLayer( false );
}
if( drill_layer == nullptr )
{
drill_layer = new EXCELLON_IMAGE( layerId );
layerId = images->AddGbrImage( drill_layer, layerId );
}
if( layerId < 0 )
@ -178,7 +185,7 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
}
// Read the Excellon drill file:
bool success = drill_Layer->LoadFile( aFullFileName );
bool success = drill_layer->LoadFile( aFullFileName );
if( !success )
{
@ -188,14 +195,13 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
}
// Display errors list
if( drill_Layer->GetMessages().size() > 0 )
if( drill_layer->GetMessages().size() > 0 )
{
HTML_MESSAGE_BOX dlg( this, _( "Error reading EXCELLON drill file" ) );
dlg.ListSet( drill_Layer->GetMessages() );
dlg.ListSet( drill_layer->GetMessages() );
dlg.ShowModal();
}
// TODO(JE) Is this the best place to add items to the view?
if( success )
{
EDA_DRAW_PANEL_GAL* canvas = GetGalCanvas();
@ -204,7 +210,7 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
{
KIGFX::VIEW* view = canvas->GetView();
for( GERBER_DRAW_ITEM* item = drill_Layer->GetItemsList(); item; item = item->Next() )
for( GERBER_DRAW_ITEM* item = drill_layer->GetItemsList(); item; item = item->Next() )
{
view->Add( (KIGFX::VIEW_ITEM*) item );
}

View File

@ -50,6 +50,10 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
gerber = new GERBER_FILE_IMAGE( layer );
images->AddGbrImage( gerber, layer );
}
else
{
Erase_Current_DrawLayer( false );
}
/* Read the gerber file */
bool success = gerber->LoadGerberFile( GERBER_FullFileName );