KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_tenting.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
25
26#include <board.h>
27#include <footprint.h>
28#include <pad.h>
29#include <pcb_track.h>
30#include <padstack.h>
33
34#include <filesystem>
35#include <fstream>
36#include <sstream>
37
38
39BOOST_AUTO_TEST_SUITE( PadTenting )
40
41
42static std::string SaveBoardToString( BOARD& aBoard )
43{
44 std::filesystem::path tempPath = std::filesystem::temp_directory_path() / "pad_tenting_test.kicad_pcb";
45 std::stringstream buf;
46
47 {
48 KI_TEST::DumpBoardToFile( aBoard, tempPath.string() );
49
50 std::ifstream ifs( tempPath );
51 buf << ifs.rdbuf();
52 }
53
54 std::filesystem::remove( tempPath );
55
56 return buf.str();
57}
58
59
63BOOST_AUTO_TEST_CASE( DefaultTentingNotSerialized )
64{
65 BOARD board;
67
68 auto fp = std::make_unique<FOOTPRINT>( &board );
69 fp->SetPosition( VECTOR2I( 0, 0 ) );
70
71 auto* pad = new PAD( fp.get() );
72 pad->SetAttribute( PAD_ATTRIB::PTH );
73 pad->SetLayerSet( PAD::PTHMask() );
75 pad->SetSize( PADSTACK::ALL_LAYERS,
76 VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
77 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.8 ), pcbIUScale.mmToIU( 0.8 ) ) );
78 pad->SetNumber( wxT( "1" ) );
79 pad->SetPosition( VECTOR2I( 0, 0 ) );
80
81 BOOST_CHECK( !pad->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
82 BOOST_CHECK( !pad->Padstack().BackOuterLayers().has_solder_mask.has_value() );
83
84 fp->Add( pad );
85 board.Add( fp.release() );
86
87 std::string output = SaveBoardToString( board );
88
89 BOOST_CHECK_MESSAGE( output.find( "(tenting" ) == std::string::npos
90 || output.find( "(tenting" ) < output.find( "(footprint" ),
91 "PTH pad with default tenting should not have a (tenting) block. "
92 "Board-level tenting in setup section is expected." );
93}
94
95
99BOOST_AUTO_TEST_CASE( ExplicitTentingSerialized )
100{
101 BOARD board;
103
104 auto fp = std::make_unique<FOOTPRINT>( &board );
105 fp->SetPosition( VECTOR2I( 0, 0 ) );
106
107 auto* pad = new PAD( fp.get() );
108 pad->SetAttribute( PAD_ATTRIB::PTH );
109 pad->SetLayerSet( PAD::PTHMask() );
111 pad->SetSize( PADSTACK::ALL_LAYERS,
112 VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
113 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.8 ), pcbIUScale.mmToIU( 0.8 ) ) );
114 pad->SetNumber( wxT( "1" ) );
115 pad->SetPosition( VECTOR2I( 0, 0 ) );
116
117 pad->Padstack().FrontOuterLayers().has_solder_mask = true;
118
119 BOOST_CHECK( pad->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
120
121 fp->Add( pad );
122 board.Add( fp.release() );
123
124 std::string output = SaveBoardToString( board );
125
126 size_t fpStart = output.find( "(footprint" );
127 BOOST_REQUIRE( fpStart != std::string::npos );
128
129 size_t tentingPos = output.find( "(tenting", fpStart );
130 BOOST_CHECK_MESSAGE( tentingPos != std::string::npos,
131 "PTH pad with explicit tenting should have a (tenting) block" );
132}
133
134
138BOOST_AUTO_TEST_CASE( NpthDefaultTentingNotSerialized )
139{
140 BOARD board;
142
143 auto fp = std::make_unique<FOOTPRINT>( &board );
144 fp->SetPosition( VECTOR2I( 0, 0 ) );
145
146 auto* pad = new PAD( fp.get() );
147 pad->SetAttribute( PAD_ATTRIB::NPTH );
148 pad->SetLayerSet( PAD::UnplatedHoleMask() );
150 pad->SetSize( PADSTACK::ALL_LAYERS,
151 VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
152 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
153 pad->SetNumber( wxT( "" ) );
154 pad->SetPosition( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ) );
155
156 BOOST_CHECK( !pad->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
157 BOOST_CHECK( !pad->Padstack().BackOuterLayers().has_solder_mask.has_value() );
158
159 fp->Add( pad );
160 board.Add( fp.release() );
161
162 std::string output = SaveBoardToString( board );
163
164 size_t fpStart = output.find( "(footprint" );
165 BOOST_REQUIRE( fpStart != std::string::npos );
166
167 size_t tentingPos = output.find( "(tenting", fpStart );
168 BOOST_CHECK_MESSAGE( tentingPos == std::string::npos,
169 "NPTH pad with default tenting should not have a (tenting) block" );
170}
171
172
176BOOST_AUTO_TEST_CASE( ViaDefaultTentingNotSerialized )
177{
178 BOARD board;
180
181 auto* via = new PCB_VIA( &board );
182 via->SetPosition( VECTOR2I( 0, 0 ) );
183 via->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.8 ) );
184 via->SetDrill( pcbIUScale.mmToIU( 0.4 ) );
185 via->SetViaType( VIATYPE::THROUGH );
186
187 BOOST_CHECK( !via->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
188 BOOST_CHECK( !via->Padstack().BackOuterLayers().has_solder_mask.has_value() );
189
190 board.Add( via );
191
192 std::string output = SaveBoardToString( board );
193
194 size_t viaStart = output.find( "(via" );
195 BOOST_REQUIRE( viaStart != std::string::npos );
196
197 size_t tentingPos = output.find( "(tenting", viaStart );
198 BOOST_CHECK_MESSAGE( tentingPos == std::string::npos,
199 "Via with default tenting should not have a (tenting) block" );
200}
201
202
206BOOST_AUTO_TEST_CASE( ViaExplicitTentingSerialized )
207{
208 BOARD board;
210
211 auto* via = new PCB_VIA( &board );
212 via->SetPosition( VECTOR2I( 0, 0 ) );
213 via->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.8 ) );
214 via->SetDrill( pcbIUScale.mmToIU( 0.4 ) );
215 via->SetViaType( VIATYPE::THROUGH );
216
217 via->Padstack().FrontOuterLayers().has_solder_mask = false;
218 via->Padstack().BackOuterLayers().has_solder_mask = false;
219
220 board.Add( via );
221
222 std::string output = SaveBoardToString( board );
223
224 size_t viaStart = output.find( "(via" );
225 BOOST_REQUIRE( viaStart != std::string::npos );
226
227 size_t tentingPos = output.find( "(tenting", viaStart );
228 BOOST_CHECK_MESSAGE( tentingPos != std::string::npos,
229 "Via with explicit tenting should have a (tenting) block" );
230}
231
232
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
@ FPHOLDER
Definition board.h:314
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1222
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:334
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:369
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:390
void DumpBoardToFile(BOARD &board, const std::string &aFilename)
Utility function to simply write a Board out to a file.
STL namespace.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ THROUGH
Definition pcb_track.h:68
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
static std::string SaveBoardToString(BOARD &aBoard)
BOOST_AUTO_TEST_CASE(DefaultTentingNotSerialized)
Pads with no explicit tenting set should not have a (tenting ...) block in the output.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695