From ec91329da0ad6e7fd98408d3d9e4b8afdf658a46 Mon Sep 17 00:00:00 2001 From: John Beard Date: Tue, 18 Dec 2018 16:37:36 +0000 Subject: [PATCH] Pcbnew: Array tool should not number NPTHs Devolve the logic as to whether a pad should be numbered or not to a pad utility function. Add a very simplistic test for this function (demonstrating how to test BOARD_ITEMs in general). Fixes: lp:1804787 * https://bugs.launchpad.net/kicad/+bug/1804787 --- pcbnew/CMakeLists.txt | 1 + pcbnew/array_creator.cpp | 4 +- pcbnew/pad_naming.cpp | 37 ++++++++++++++ pcbnew/pad_naming.h | 50 +++++++++++++++++++ qa/pcbnew/CMakeLists.txt | 1 + qa/pcbnew/test_pad_naming.cpp | 90 +++++++++++++++++++++++++++++++++++ 6 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 pcbnew/pad_naming.cpp create mode 100644 pcbnew/pad_naming.h create mode 100644 qa/pcbnew/test_pad_naming.cpp diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 8c518d1bfd..a52f4b35f5 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -280,6 +280,7 @@ set( PCBNEW_CLASS_SRCS onleftclick.cpp onrightclick.cpp pad_edit_functions.cpp + pad_naming.cpp pcb_base_edit_frame.cpp pcb_footprint_edit_utils.cpp pcb_layer_box_selector.cpp diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 94c9979ef4..169a60e8b7 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -27,7 +27,9 @@ */ #include "array_creator.h" + #include +#include #include @@ -108,7 +110,7 @@ void ARRAY_CREATOR::Invoke() { D_PAD* pad = static_cast( new_item ); - if( !pad->IsAperturePad() ) + if( PAD_NAMING::PadCanHaveName( *pad ) ) pad->SetName( array_opts->GetItemNumber( ptN ) ); } } diff --git a/pcbnew/pad_naming.cpp b/pcbnew/pad_naming.cpp new file mode 100644 index 0000000000..8be04d4197 --- /dev/null +++ b/pcbnew/pad_naming.cpp @@ -0,0 +1,37 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "pad_naming.h" + +bool PAD_NAMING::PadCanHaveName( const D_PAD& aPad ) +{ + // Aperture pads don't get a number + if( aPad.IsAperturePad() ) + return false; + + // NPTH pads don't get numbers + if( aPad.GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) + return false; + + return true; +} \ No newline at end of file diff --git a/pcbnew/pad_naming.h b/pcbnew/pad_naming.h new file mode 100644 index 0000000000..de704aa1b8 --- /dev/null +++ b/pcbnew/pad_naming.h @@ -0,0 +1,50 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef PAD_NAMING_H +#define PAD_NAMING_H + +#include + +/** + * The PAD_NAMING namespace contains helper functions for common operations + * to do with naming of #D_PAD objects. + */ +namespace PAD_NAMING +{ + +/** + * Check if a pad should be named. + * + * For example, NPTH or paste apertures normally do not have names, as they + * cannot be assigned to a netlist. + * + * @param aPad the pad to check + * @return true if the pad gets a name + */ +bool PadCanHaveName( const D_PAD& aPad ); + +} // namespace PAD_NAMING + +#endif // PAD_NAMING_H \ No newline at end of file diff --git a/qa/pcbnew/CMakeLists.txt b/qa/pcbnew/CMakeLists.txt index eecdb17677..6402eea24f 100644 --- a/qa/pcbnew/CMakeLists.txt +++ b/qa/pcbnew/CMakeLists.txt @@ -35,6 +35,7 @@ add_executable( qa_pcbnew ../../common/observable.cpp test_graphics_import_mgr.cpp + test_pad_naming.cpp ) if( BUILD_GITHUB_PLUGIN ) diff --git a/qa/pcbnew/test_pad_naming.cpp b/qa/pcbnew/test_pad_naming.cpp new file mode 100644 index 0000000000..d49f8873e4 --- /dev/null +++ b/qa/pcbnew/test_pad_naming.cpp @@ -0,0 +1,90 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include + +#include +#include +#include + +struct PAD_FIXTURE +{ + PAD_FIXTURE() : m_board(), m_module( &m_board ) + { + } + + D_PAD MakeNPTH() + { + D_PAD pad( &m_module ); + + pad.SetAttribute( PAD_ATTRIB_HOLE_NOT_PLATED ); + pad.SetLayerSet( D_PAD::UnplatedHoleMask() ); + + return pad; + } + + D_PAD MakeAperture() + { + D_PAD pad( &m_module ); + + pad.SetAttribute( PAD_ATTRIB_STANDARD ); + pad.SetLayerSet( D_PAD::ApertureMask() ); + + return pad; + } + + D_PAD MakeSmd() + { + D_PAD pad( &m_module ); + + pad.SetAttribute( PAD_ATTRIB_SMD ); + pad.SetLayerSet( D_PAD::SMDMask() ); + + return pad; + } + + BOARD m_board; + MODULE m_module; +}; + + +BOOST_FIXTURE_TEST_SUITE( PadNaming, PAD_FIXTURE ) + +/** + * Check what gets names and what doesn't + */ +BOOST_AUTO_TEST_CASE( CanName ) +{ + auto npth = MakeNPTH(); + BOOST_CHECK_EQUAL( false, PAD_NAMING::PadCanHaveName( npth ) ); + + auto aperture = MakeAperture(); + BOOST_CHECK_EQUAL( false, PAD_NAMING::PadCanHaveName( aperture ) ); + + auto smd = MakeSmd(); + BOOST_CHECK_EQUAL( true, PAD_NAMING::PadCanHaveName( smd ) ); +} + + +BOOST_AUTO_TEST_SUITE_END()