KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_size_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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
24
#include <
qa_utils/wx_utils/unit_test_utils.h
>
25
26
#include <
board.h
>
27
#include <
footprint.h
>
28
#include <
pad.h
>
29
30
#include <memory>
31
32
BOOST_AUTO_TEST_SUITE
( PadSizeSetters )
33
34
// Regression test for GitLab #24333: editing a circular pad's diameter via the
35
// Properties panel calls PAD::SetSizeX with a single dimension. SetSizeX must
36
// keep the orthogonal dimension in lock-step for CIRCLE pads, otherwise DRC
37
// (e.g. annular-width) reads a stale Y and reports incorrect measurements.
38
BOOST_AUTO_TEST_CASE
( SetSizeXOnCirclePadUpdatesY )
39
{
40
BOARD
board;
41
board.
SetBoardUse
(
BOARD_USE::FPHOLDER
);
42
43
auto
fp = std::make_unique<FOOTPRINT>( &board );
44
auto
pad
= std::make_unique<PAD>( fp.get() );
45
46
pad
->SetAttribute(
PAD_ATTRIB::PTH
);
47
pad
->SetLayerSet(
PAD::PTHMask
() );
48
pad
->SetShape(
PADSTACK::ALL_LAYERS
,
PAD_SHAPE::CIRCLE
);
49
pad
->SetSize(
PADSTACK::ALL_LAYERS
,
VECTOR2I
(
pcbIUScale
.mmToIU( 1.0 ),
pcbIUScale
.mmToIU( 1.0 ) ) );
50
51
pad
->SetSizeX(
pcbIUScale
.mmToIU( 1.5 ) );
52
53
BOOST_CHECK_EQUAL
(
pad
->GetSizeX(),
pcbIUScale
.mmToIU( 1.5 ) );
54
BOOST_CHECK_EQUAL
(
pad
->GetSizeY(),
pcbIUScale
.mmToIU( 1.5 ) );
55
}
56
57
58
// Mirror of the above. SetSizeY is hidden from the panel for CIRCLE pads via
59
// SetAvailableFunc, but the public setter still needs to honour the invariant.
60
BOOST_AUTO_TEST_CASE
( SetSizeYOnCirclePadUpdatesX )
61
{
62
BOARD
board;
63
board.
SetBoardUse
(
BOARD_USE::FPHOLDER
);
64
65
auto
fp = std::make_unique<FOOTPRINT>( &board );
66
auto
pad
= std::make_unique<PAD>( fp.get() );
67
68
pad
->SetAttribute(
PAD_ATTRIB::PTH
);
69
pad
->SetLayerSet(
PAD::PTHMask
() );
70
pad
->SetShape(
PADSTACK::ALL_LAYERS
,
PAD_SHAPE::CIRCLE
);
71
pad
->SetSize(
PADSTACK::ALL_LAYERS
,
VECTOR2I
(
pcbIUScale
.mmToIU( 1.0 ),
pcbIUScale
.mmToIU( 1.0 ) ) );
72
73
pad
->SetSizeY(
pcbIUScale
.mmToIU( 1.5 ) );
74
75
BOOST_CHECK_EQUAL
(
pad
->GetSizeX(),
pcbIUScale
.mmToIU( 1.5 ) );
76
BOOST_CHECK_EQUAL
(
pad
->GetSizeY(),
pcbIUScale
.mmToIU( 1.5 ) );
77
}
78
79
80
// Guard against the fix over-applying: non-circular shapes have independently
81
// meaningful X and Y, so SetSizeX must not touch Y.
82
BOOST_AUTO_TEST_CASE
( SetSizeXOnRectPadLeavesYAlone )
83
{
84
BOARD
board;
85
board.
SetBoardUse
(
BOARD_USE::FPHOLDER
);
86
87
auto
fp = std::make_unique<FOOTPRINT>( &board );
88
auto
pad
= std::make_unique<PAD>( fp.get() );
89
90
pad
->SetAttribute(
PAD_ATTRIB::SMD
);
91
pad
->SetLayerSet(
LSET
( {
F_Cu
} ) );
92
pad
->SetShape(
PADSTACK::ALL_LAYERS
,
PAD_SHAPE::RECTANGLE
);
93
pad
->SetSize(
PADSTACK::ALL_LAYERS
,
VECTOR2I
(
pcbIUScale
.mmToIU( 1.0 ),
pcbIUScale
.mmToIU( 0.5 ) ) );
94
95
pad
->SetSizeX(
pcbIUScale
.mmToIU( 1.5 ) );
96
97
BOOST_CHECK_EQUAL
(
pad
->GetSizeX(),
pcbIUScale
.mmToIU( 1.5 ) );
98
BOOST_CHECK_EQUAL
(
pad
->GetSizeY(),
pcbIUScale
.mmToIU( 0.5 ) );
99
}
100
101
BOOST_AUTO_TEST_SUITE_END
()
pcbIUScale
constexpr EDA_IU_SCALE pcbIUScale
Definition
base_units.h:125
BITMAPS::pad
@ pad
Definition
bitmaps_list.h:416
board.h
BOARD_USE::FPHOLDER
@ FPHOLDER
Definition
board.h:315
BOARD
Information pertinent to a Pcbnew printed circuit board.
Definition
board.h:323
BOARD::SetBoardUse
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition
board.h:335
LSET
LSET is a set of PCB_LAYER_IDs.
Definition
lset.h:37
PADSTACK::ALL_LAYERS
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition
padstack.h:177
PAD::PTHMask
static LSET PTHMask()
layer set for a through hole pad
Definition
pad.cpp:368
footprint.h
F_Cu
@ F_Cu
Definition
layer_ids.h:64
pad.h
PAD_ATTRIB::SMD
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition
padstack.h:99
PAD_ATTRIB::PTH
@ PTH
Plated through hole pad.
Definition
padstack.h:98
PAD_SHAPE::CIRCLE
@ CIRCLE
Definition
padstack.h:53
PAD_SHAPE::RECTANGLE
@ RECTANGLE
Definition
padstack.h:54
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(SetSizeXOnCirclePadUpdatesY)
Definition
test_pad_size_setters.cpp:38
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:687
src
qa
tests
pcbnew
test_pad_size_setters.cpp
Generated on Mon May 25 2026 00:06:19 for KiCad PCB EDA Suite by
1.13.2