KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_setters.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <board.h>
23#include <footprint.h>
24#include <pad.h>
25
26#include <memory>
27
28BOOST_AUTO_TEST_SUITE( PadSetters )
29
30// Regression test for GitLab #24333: editing a circular pad's diameter via the
31// Properties panel calls PAD::SetSizeX with a single dimension. SetSizeX must
32// keep the orthogonal dimension in lock-step for CIRCLE pads, otherwise DRC
33// (e.g. annular-width) reads a stale Y and reports incorrect measurements.
34BOOST_AUTO_TEST_CASE( SetSizeXOnCirclePadUpdatesY )
35{
36 BOARD board;
38
39 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( &board );
40 std::unique_ptr<PAD> pad = std::make_unique<PAD>( fp.get() );
41
42 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
43 pad->SetAttribute( PAD_ATTRIB::PTH );
44 pad->SetLayerSet( PAD::PTHMask() );
46 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
47
48 pad->SetSizeXProp( pcbIUScale.mmToIU( 1.5 ) );
49
50 BOOST_CHECK_EQUAL( pad->GetSizeXProp(), pcbIUScale.mmToIU( 1.5 ) );
51 BOOST_CHECK_EQUAL( pad->GetSizeYProp(), pcbIUScale.mmToIU( 1.5 ) );
52}
53
54
55// Mirror of the above. SetSizeY is hidden from the panel for CIRCLE pads via
56// SetAvailableFunc, but the public setter still needs to honour the invariant.
57BOOST_AUTO_TEST_CASE( SetSizeYOnCirclePadUpdatesX )
58{
59 BOARD board;
61
62 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( &board );
63 std::unique_ptr<PAD> pad = std::make_unique<PAD>( fp.get() );
64
65 pad->SetAttribute( PAD_ATTRIB::PTH );
66 pad->SetLayerSet( PAD::PTHMask() );
68 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
69
70 pad->SetSizeYProp( pcbIUScale.mmToIU( 1.5 ) );
71
72 BOOST_CHECK_EQUAL( pad->GetSizeXProp(), pcbIUScale.mmToIU( 1.5 ) );
73 BOOST_CHECK_EQUAL( pad->GetSizeYProp(), pcbIUScale.mmToIU( 1.5 ) );
74}
75
76
77// Guard against the fix over-applying: non-circular shapes have independently
78// meaningful X and Y, so SetSizeX must not touch Y.
79BOOST_AUTO_TEST_CASE( SetSizeXOnRectPadLeavesYAlone )
80{
81 BOARD board;
83
84 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( &board );
85 std::unique_ptr<PAD> pad = std::make_unique<PAD>( fp.get() );
86
87 pad->SetAttribute( PAD_ATTRIB::SMD );
88 pad->SetLayerSet( LSET( { F_Cu } ) );
90 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 0.5 ) ) );
91
92 pad->SetSizeXProp( pcbIUScale.mmToIU( 1.5 ) );
93
94 BOOST_CHECK_EQUAL( pad->GetSizeXProp(), pcbIUScale.mmToIU( 1.5 ) );
95 BOOST_CHECK_EQUAL( pad->GetSizeYProp(), pcbIUScale.mmToIU( 0.5 ) );
96}
97
98
99// PAD::SetAttribute() must drop all drilling when the new type has no hole.
100// This is used (for example) when parsing an SMD pad as the pad starts as PTH
101// and then changes to SMD, which has no hole.
102BOOST_AUTO_TEST_CASE( SetAttributeClearsAllDrilling )
103{
104 BOARD board;
106
107 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( &board );
108 std::unique_ptr<PAD> pad = std::make_unique<PAD>( fp.get() );
109
110 // Start with a plated through-hole pad with a drill and post-machining
111 pad->SetAttribute( PAD_ATTRIB::PTH );
112 pad->SetLayerSet( PAD::PTHMask() );
113 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
114
115 // Set up "some" drilling and post-machining features
116 pad->Padstack().SetBackdrillSize( true, pcbIUScale.mmToIU( 1.2 ) );
117 pad->Padstack().SetBackdrillEndLayer( true, In1_Cu );
118 pad->Padstack().FrontPostMachining().mode = PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE;
119 pad->Padstack().FrontPostMachining().size = pcbIUScale.mmToIU( 1.5 );
120
121 // Switch to SMD, which has no hole
122 pad->SetAttribute( PAD_ATTRIB::SMD );
123
124 // All drilling and post-machining features should be cleared
125 BOOST_CHECK_EQUAL( pad->GetDrillSize().x, 0 );
126 BOOST_CHECK_EQUAL( pad->GetDrillSize().y, 0 );
127 BOOST_CHECK_EQUAL( pad->Padstack().SecondaryDrill().size.x, 0 );
128 BOOST_CHECK( !pad->Padstack().FrontPostMachining().mode.has_value() );
129 BOOST_CHECK_EQUAL( pad->Padstack().FrontPostMachining().size, 0 );
130}
131
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ FPHOLDER
Definition board.h:403
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:423
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:170
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:615
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:98
@ PTH
Plated through hole pad.
Definition padstack.h:97
@ RECTANGLE
Definition padstack.h:53
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SetSizeXOnCirclePadUpdatesY)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708