← Back to team overview

kicad-developers team mailing list archive

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

 

Fixes: https://bugs.launchpad.net/kicad/+bug/1747443

-Jon
From 781adc8252bace405d30ba9e8878265fac73be4e Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Thu, 22 Feb 2018 19:31:51 -0500
Subject: [PATCH] Clear out old layer data when loading on top of an existing
 image

Fixes: lp:1747443
* https://bugs.launchpad.net/kicad/+bug/1747443
---
 gerbview/excellon_read_drill_file.cpp | 24 +++++++++++++++---------
 gerbview/readgerb.cpp                 |  4 ++++
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp
index 8895ff394..f444de64c 100644
--- a/gerbview/excellon_read_drill_file.cpp
+++ b/gerbview/excellon_read_drill_file.cpp
@@ -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 );
             }
diff --git a/gerbview/readgerb.cpp b/gerbview/readgerb.cpp
index 293c4a40e..f3209bf5c 100644
--- a/gerbview/readgerb.cpp
+++ b/gerbview/readgerb.cpp
@@ -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 );
-- 
2.14.1


Follow ups