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
29BOOST_AUTO_TEST_SUITE( PthHoleSize )
30
31BOOST_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;
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
56 BOOST_CHECK_CLOSE( pcbIUScale.IUTomm( hole ), 1.0, 0.1 );
57}
58
59BOOST_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;
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
80 BOOST_CHECK_CLOSE( pcbIUScale.IUTomm( hole ), 1.35, 0.1 );
81}
82
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
A source of hole size rules for a plated through hole.
virtual int GetLevelCount() const =0
virtual PTH_HOLE_SIZE_RESULT ComputeHoleSize(int aLevel, const PTH_LEAD_DEF &aLead) const =0
Compute the allowable hole size range for a lead.
int ComputeRecommendedPthHoleSize(const PTH_HOLE_SIZE_RESULT &aRange, int aRoundingStep, PTH_HOLE_ROUNDING aRounding)
Choose a recommended hole within an allowable range.
const PTH_HOLE_SIZE_STANDARD * FindPthHoleSizeStandard(const wxString &aId)
Find a hole size standard in the registry by its ID (e.g.
PTH_LEAD_SHAPE m_shape
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Ipc2222RectangularLead)
Tests for the plated through hole size rules, based on the worked example in the KiCad libraries wiki...
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")