← Back to team overview

kicad-developers team mailing list archive

[PATCH] Fix warning for some pads with no copper layer

 

D_PAD::ViewGetLayers tries to handle the case of a pad that exists only on mechanical layers, but misses a few (silkscreen, Dwgs.User, Eco1/2.User). Even if putting a pad on these layers is perhaps not the best idea, the footprint editor does allow it, so internal errors shouldn't be raised if you do it. Here's a patch that adds these layers to the list of layers examined.

Also restructures the code a bit, it was very much a WET - We Enjoy Typing! - design... made to loop over the list of layers.

It's still possible to get an invalid configuration if one were to hand-edit the file, so I also edited the error message that is displayed to make it perhaps a bit more helpful.

--
Chris
commit 779ab9528dc86fe16ccd4c411aa10ca04ef144d4
Author: Chris Pavlina <cpavlin1@xxxxxxxxxxxxxx>
Date:   Tue May 26 10:26:10 2015 -0400

    Eliminate "PAD has no layer" warning for valid pads

diff --git a/include/view/view_item.h b/include/view/view_item.h
index 5846d19..878c8e7 100644
--- a/include/view/view_item.h
+++ b/include/view/view_item.h
@@ -123,7 +123,7 @@ public:
     /**
      * Function ViewGetLayers()
      * Returns the all the layers within the VIEW the object is painted on. For instance, a D_PAD
-     * spans one or more copper layers and a few technical layers. ViewDraw() or PAINTER::Draw() is
+     * spans zero or more copper layers and a few technical layers. ViewDraw() or PAINTER::Draw() is
      * repeatedly called for each of the layers returned by ViewGetLayers(), depending on the
      * rendering order.
      * @param aLayers[]: output layer index array
diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp
index e2d7556..9845a72 100644
--- a/pcbnew/class_pad.cpp
+++ b/pcbnew/class_pad.cpp
@@ -47,6 +47,7 @@
 #include <class_module.h>
 #include <polygon_test_point_inside.h>
 #include <convert_from_iu.h>
+#include <boost/foreach.hpp>
 
 
 int D_PAD::m_PadSketchModePenSize = 0;      // Pen size used to draw pads in sketch mode
@@ -950,28 +951,25 @@ void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const
         aLayers[aCount++] = NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE );
     }
 
-    if( IsOnLayer( F_Mask ) )
-        aLayers[aCount++] = F_Mask;
+    // Check non-copper layers. This list should include all the layers that the
+    // footprint editor allows a pad to be placed on.
+    static const LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
+        F_Adhes, B_Adhes, F_SilkS, B_SilkS, Dwgs_User, Eco1_User, Eco2_User };
 
-    if( IsOnLayer( B_Mask ) )
-        aLayers[aCount++] = B_Mask;
-
-    if( IsOnLayer( F_Paste ) )
-        aLayers[aCount++] = F_Paste;
-
-    if( IsOnLayer( B_Paste ) )
-        aLayers[aCount++] = B_Paste;
-
-    if( IsOnLayer( B_Adhes ) )
-        aLayers[aCount++] = B_Adhes;
-
-    if( IsOnLayer( F_Adhes ) )
-        aLayers[aCount++] = F_Adhes;
+    BOOST_FOREACH( LAYER_ID each_layer, layers_mech )
+    {
+        if( IsOnLayer( each_layer ) )
+            aLayers[aCount++] = each_layer;
+    }
 
 #ifdef __WXDEBUG__
     if( aCount == 0 )    // Should not occur
     {
-        wxLogWarning( wxT("D_PAD::ViewGetLayers():PAD has no layer") );
+        wxString msg;
+        msg.Printf( wxT( "footprint %s, pad %s: could not find valid layer for pad" ),
+                GetParent()->GetReference(),
+                GetPadName().IsEmpty() ? "(unnamed)" : GetPadName() );
+        wxLogWarning( msg );
     }
 #endif
 }

Follow ups