← Back to team overview

kicad-developers team mailing list archive

[PATCH] Fix for bug/1754049

 

https://bugs.launchpad.net/kicad/+bug/1754049

This patch follows the edict (stated in dialog_layers_setup.cpp) that items
on a layer that is removed must be deleted.
From 2a77ec7609cccf70f17d7e830237006c1d72d528 Mon Sep 17 00:00:00 2001
From: hauptmech <hauptmech@xxxxxxxxx>
Date: Wed, 14 Mar 2018 22:31:59 +1300
Subject: [PATCH] Fix Layer setup can be changed leading to data loss Edit
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.16.2"

This is a multi-part message in MIME format.
--------------2.16.2
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


Check for items inside modules and delete them if they belong to the layer we are removing.
Pads get the offending layer removed from their layers list and deleted if they have no more layers.

Fixes: lp:1754049
https://bugs.launchpad.net/kicad/+bug/1754049
---
 pcbnew/collectors.cpp                  | 14 +++++++++++++-
 pcbnew/dialogs/dialog_layers_setup.cpp | 26 +++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)


--------------2.16.2
Content-Type: text/x-patch; name="0001-Fix-Layer-setup-can-be-changed-leading-to-data-loss-.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Fix-Layer-setup-can-be-changed-leading-to-data-loss-.patch"

diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp
index 2219886c2..a19efbdd7 100644
--- a/pcbnew/collectors.cpp
+++ b/pcbnew/collectors.cpp
@@ -65,6 +65,9 @@ const KICAD_T GENERAL_COLLECTOR::BoardLevelItems[] = {
     PCB_VIA_T,
     PCB_TRACE_T,
     PCB_MODULE_T,
+    PCB_MODULE_TEXT_T,
+    PCB_MODULE_EDGE_T,
+    PCB_PAD_T,
     PCB_ZONE_T,
     PCB_ZONE_AREA_T,
     EOT
@@ -499,7 +502,16 @@ SEARCH_RESULT PCB_LAYER_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )
 {
     BOARD_ITEM* item = (BOARD_ITEM*) testItem;
 
-    if( item->GetLayer() == m_layer_id )
+    if( item->Type() == PCB_PAD_T )
+    {
+        D_PAD* pad = nullptr;
+
+        wxASSERT( !pad );
+        pad = static_cast<D_PAD*>( item );
+        if ( pad->GetLayerSet()[m_layer_id] )
+            Append( testItem );
+    }
+    else if( item->GetLayer() == m_layer_id )
         Append( testItem );
 
     return SEARCH_CONTINUE;
diff --git a/pcbnew/dialogs/dialog_layers_setup.cpp b/pcbnew/dialogs/dialog_layers_setup.cpp
index 28b4d2d33..a62fe5645 100644
--- a/pcbnew/dialogs/dialog_layers_setup.cpp
+++ b/pcbnew/dialogs/dialog_layers_setup.cpp
@@ -35,6 +35,7 @@
 #include <collectors.h>
 
 #include <dialog_layers_setup_base.h>
+#include <class_module.h>
 
 
 // some define to choose how copper layers widgets are shown
@@ -655,7 +656,30 @@ bool DIALOG_LAYERS_SETUP::TransferDataFromWindow()
             if( collector.GetCount() != 0 )
             {
                 for( int i = 0; i < collector.GetCount(); i++ )
-                    m_pcb->Remove( collector[i] );
+                    if( collector[i]->Type() == PCB_PAD_T )
+                    {
+                        //pads are multi-layer items that need to be handled specially
+                        D_PAD* pad = nullptr;
+
+                        wxASSERT( !pad );
+                        pad = static_cast<D_PAD*>( collector[i] );
+                        pad->SetLayerSet( pad->GetLayerSet().set( layer_id, false ) );
+                        if( pad->GetLayerSet().count() == 0 )
+                            pad->GetParent()->Remove(pad);
+                    }
+                    else if( collector[i]->Type() == PCB_MODULE_TEXT_T )
+                    {
+                        if( static_cast<TEXTE_MODULE*>( collector[i] )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
+                            collector[i]->GetParent()->Remove( collector[i] );
+                    }
+                    else if( collector[i]->Type() == PCB_MODULE_EDGE_T )
+                    {
+                        collector[i]->GetParent()->Remove( collector[i] );
+                    }
+                    else
+                    {
+                        m_pcb->Remove( collector[i] );
+                    }
             }
         }
     }

--------------2.16.2--



Follow ups