KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pth_hole_size.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 modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation, either version 3 of the License, or (at your
9
* option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* 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
20
#include <boost/test/unit_test.hpp>
21
22
#include <
base_units.h
>
23
#include <
pth_hole_size.h
>
24
29
BOOST_AUTO_TEST_SUITE
( PthHoleSize )
30
31
BOOST_AUTO_TEST_CASE
( Ipc2222RectangularLead )
32
{
33
const
PTH_HOLE_SIZE_STANDARD
* standard =
FindPthHoleSizeStandard
(
"IPC-2222B"
);
34
35
BOOST_REQUIRE
( standard );
36
BOOST_CHECK_EQUAL
( standard->
GetLevelCount
(), 3 );
37
38
// Recom RBE module lead: 0.51 x 0.25 mm nominal with tolerances, so the diagonal ranges
39
// from sqrt(0.46^2 + 0.20^2) to sqrt(0.61^2 + 0.30^2).
40
PTH_LEAD_DEF
lead;
41
lead.
m_shape
=
PTH_LEAD_SHAPE::RECTANGULAR
;
42
lead.
m_minX
=
pcbIUScale
.mmToIU( 0.46 );
43
lead.
m_maxX
=
pcbIUScale
.mmToIU( 0.61 );
44
lead.
m_minY
=
pcbIUScale
.mmToIU( 0.20 );
45
lead.
m_maxY
=
pcbIUScale
.mmToIU( 0.30 );
46
47
// Level B (moderate density), rounding to 0.1 mm.
48
PTH_HOLE_SIZE_RESULT
result
= standard->
ComputeHoleSize
( 1, lead );
49
50
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_leadMin ), 0.5016, 0.1 );
51
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_leadMax ), 0.6798, 0.1 );
52
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_holeMin ), 0.8798, 0.1 );
53
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_holeMax ), 1.2016, 0.1 );
54
55
const
int
hole =
ComputeRecommendedPthHoleSize
(
result
,
pcbIUScale
.mmToIU( 0.1 ),
PTH_HOLE_ROUNDING::NEAREST
);
56
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm( hole ), 1.0, 0.1 );
57
}
58
59
BOOST_AUTO_TEST_CASE
( Ipc2222SquareLead )
60
{
61
const
PTH_HOLE_SIZE_STANDARD
* standard =
FindPthHoleSizeStandard
(
"IPC-2222B"
);
62
63
BOOST_REQUIRE
( standard );
64
65
// A 0.64 mm nominal 0.1" header pin; the diagonal is the size that must fit in the hole.
66
PTH_LEAD_DEF
lead;
67
lead.
m_shape
=
PTH_LEAD_SHAPE::SQUARE
;
68
lead.
m_minX
=
pcbIUScale
.mmToIU( 0.60 );
69
lead.
m_maxX
=
pcbIUScale
.mmToIU( 0.65 );
70
71
// Level B, rounding to 0.05 mm.
72
PTH_HOLE_SIZE_RESULT
result
= standard->
ComputeHoleSize
( 1, lead );
73
74
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_leadMin ), 0.8485, 0.1 );
75
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_leadMax ), 0.9192, 0.1 );
76
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_holeMin ), 1.1192, 0.1 );
77
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm(
result
.m_holeMax ), 1.5485, 0.1 );
78
79
const
int
hole =
ComputeRecommendedPthHoleSize
(
result
,
pcbIUScale
.mmToIU( 0.05 ),
PTH_HOLE_ROUNDING::NEAREST
);
80
BOOST_CHECK_CLOSE(
pcbIUScale
.IUTomm( hole ), 1.35, 0.1 );
81
}
82
83
BOOST_AUTO_TEST_SUITE_END
()
base_units.h
pcbIUScale
constexpr EDA_IU_SCALE pcbIUScale
Definition
base_units.h:121
PTH_HOLE_SIZE_STANDARD
A source of hole size rules for a plated through hole.
Definition
pth_hole_size.h:71
PTH_HOLE_SIZE_STANDARD::GetLevelCount
virtual int GetLevelCount() const =0
PTH_HOLE_SIZE_STANDARD::ComputeHoleSize
virtual PTH_HOLE_SIZE_RESULT ComputeHoleSize(int aLevel, const PTH_LEAD_DEF &aLead) const =0
Compute the allowable hole size range for a lead.
ComputeRecommendedPthHoleSize
int ComputeRecommendedPthHoleSize(const PTH_HOLE_SIZE_RESULT &aRange, int aRoundingStep, PTH_HOLE_ROUNDING aRounding)
Choose a recommended hole within an allowable range.
Definition
pth_hole_size.cpp:129
FindPthHoleSizeStandard
const PTH_HOLE_SIZE_STANDARD * FindPthHoleSizeStandard(const wxString &aId)
Find a hole size standard in the registry by its ID (e.g.
Definition
pth_hole_size.cpp:152
pth_hole_size.h
PTH_LEAD_SHAPE::SQUARE
@ SQUARE
Definition
pth_hole_size.h:32
PTH_LEAD_SHAPE::RECTANGULAR
@ RECTANGULAR
Definition
pth_hole_size.h:33
PTH_HOLE_ROUNDING::NEAREST
@ NEAREST
Definition
pth_hole_size.h:40
PTH_HOLE_SIZE_RESULT
Definition
pth_hole_size.h:57
PTH_LEAD_DEF
Definition
pth_hole_size.h:45
PTH_LEAD_DEF::m_maxY
int m_maxY
Definition
pth_hole_size.h:50
PTH_LEAD_DEF::m_maxX
int m_maxX
Definition
pth_hole_size.h:48
PTH_LEAD_DEF::m_minY
int m_minY
Definition
pth_hole_size.h:49
PTH_LEAD_DEF::m_shape
PTH_LEAD_SHAPE m_shape
Definition
pth_hole_size.h:46
PTH_LEAD_DEF::m_minX
int m_minX
Definition
pth_hole_size.h:47
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:79
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Ipc2222RectangularLead)
Tests for the plated through hole size rules, based on the worked example in the KiCad libraries wiki...
Definition
test_pth_hole_size.cpp:31
result
wxString result
Test unit parsing edge cases and error handling.
Definition
test_text_eval_numeric_compat.cpp:598
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
src
qa
tests
common
test_pth_hole_size.cpp
Generated on Thu Sep 17 2026 00:06:24 for KiCad PCB EDA Suite by
1.13.2