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, 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( PadSizeSetters )
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 auto fp = std::make_unique<FOOTPRINT>( &board );
40 auto pad = std::make_unique<PAD>( fp.get() );
41
42 pad->SetAttribute( PAD_ATTRIB::PTH );
43 pad->SetLayerSet( PAD::PTHMask() );
45 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
46
47 pad->SetSizeX( pcbIUScale.mmToIU( 1.5 ) );
48
49 BOOST_CHECK_EQUAL( pad->GetSizeX(), pcbIUScale.mmToIU( 1.5 ) );
50 BOOST_CHECK_EQUAL( pad->GetSizeY(), pcbIUScale.mmToIU( 1.5 ) );
51}
52
53
54// Mirror of the above. SetSizeY is hidden from the panel for CIRCLE pads via
55// SetAvailableFunc, but the public setter still needs to honour the invariant.
56BOOST_AUTO_TEST_CASE( SetSizeYOnCirclePadUpdatesX )
57{
58 BOARD board;
60
61 auto fp = std::make_unique<FOOTPRINT>( &board );
62 auto pad = std::make_unique<PAD>( fp.get() );
63
64 pad->SetAttribute( PAD_ATTRIB::PTH );
65 pad->SetLayerSet( PAD::PTHMask() );
67 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
68
69 pad->SetSizeY( pcbIUScale.mmToIU( 1.5 ) );
70
71 BOOST_CHECK_EQUAL( pad->GetSizeX(), pcbIUScale.mmToIU( 1.5 ) );
72 BOOST_CHECK_EQUAL( pad->GetSizeY(), pcbIUScale.mmToIU( 1.5 ) );
73}
74
75
76// Guard against the fix over-applying: non-circular shapes have independently
77// meaningful X and Y, so SetSizeX must not touch Y.
78BOOST_AUTO_TEST_CASE( SetSizeXOnRectPadLeavesYAlone )
79{
80 BOARD board;
82
83 auto fp = std::make_unique<FOOTPRINT>( &board );
84 auto pad = std::make_unique<PAD>( fp.get() );
85
86 pad->SetAttribute( PAD_ATTRIB::SMD );
87 pad->SetLayerSet( LSET( { F_Cu } ) );
89 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 0.5 ) ) );
90
91 pad->SetSizeX( pcbIUScale.mmToIU( 1.5 ) );
92
93 BOOST_CHECK_EQUAL( pad->GetSizeX(), pcbIUScale.mmToIU( 1.5 ) );
94 BOOST_CHECK_EQUAL( pad->GetSizeY(), pcbIUScale.mmToIU( 0.5 ) );
95}
96
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
@ FPHOLDER
Definition board.h:312
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:320
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:332
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:579
@ F_Cu
Definition layer_ids.h:60
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:99
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ RECTANGLE
Definition padstack.h:54
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:683