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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <board.h>
23#include <footprint.h>
24#include <pad.h>
25#include <pcb_track.h>
26#include <padstack.h>
29
30#include <filesystem>
31#include <fstream>
32#include <sstream>
33
34
35BOOST_AUTO_TEST_SUITE( PadTenting )
36
37
38static std::string SaveBoardToString( BOARD& aBoard )
39{
40 std::filesystem::path tempPath = std::filesystem::temp_directory_path() / "pad_tenting_test.kicad_pcb";
41 std::stringstream buf;
42
43 {
44 KI_TEST::DumpBoardToFile( aBoard, tempPath.string() );
45
46 std::ifstream ifs( tempPath );
47 buf << ifs.rdbuf();
48 }
49
50 std::filesystem::remove( tempPath );
51
52 return buf.str();
53}
54
55
59BOOST_AUTO_TEST_CASE( DefaultTentingNotSerialized )
60{
61 BOARD board;
63
64 auto fp = std::make_unique<FOOTPRINT>( &board );
65 fp->SetPosition( VECTOR2I( 0, 0 ) );
66
67 auto* pad = new PAD( fp.get() );
68 pad->SetAttribute( PAD_ATTRIB::PTH );
69 pad->SetLayerSet( PAD::PTHMask() );
71 pad->SetSize( PADSTACK::ALL_LAYERS,
72 VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
73 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.8 ), pcbIUScale.mmToIU( 0.8 ) ) );
74 pad->SetNumber( wxT( "1" ) );
75 pad->SetPosition( VECTOR2I( 0, 0 ) );
76
77 BOOST_CHECK( !pad->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
78 BOOST_CHECK( !pad->Padstack().BackOuterLayers().has_solder_mask.has_value() );
79
80 fp->Add( pad );
81 board.Add( fp.release() );
82
83 std::string output = SaveBoardToString( board );
84
85 BOOST_CHECK_MESSAGE( output.find( "(tenting" ) == std::string::npos
86 || output.find( "(tenting" ) < output.find( "(footprint" ),
87 "PTH pad with default tenting should not have a (tenting) block. "
88 "Board-level tenting in setup section is expected." );
89}
90
91
95BOOST_AUTO_TEST_CASE( ExplicitTentingSerialized )
96{
97 BOARD board;
99
100 auto fp = std::make_unique<FOOTPRINT>( &board );
101 fp->SetPosition( VECTOR2I( 0, 0 ) );
102
103 auto* pad = new PAD( fp.get() );
104 pad->SetAttribute( PAD_ATTRIB::PTH );
105 pad->SetLayerSet( PAD::PTHMask() );
107 pad->SetSize( PADSTACK::ALL_LAYERS,
108 VECTOR2I( pcbIUScale.mmToIU( 1.5 ), pcbIUScale.mmToIU( 1.5 ) ) );
109 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 0.8 ), pcbIUScale.mmToIU( 0.8 ) ) );
110 pad->SetNumber( wxT( "1" ) );
111 pad->SetPosition( VECTOR2I( 0, 0 ) );
112
113 pad->Padstack().FrontOuterLayers().has_solder_mask = true;
114
115 BOOST_CHECK( pad->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
116
117 fp->Add( pad );
118 board.Add( fp.release() );
119
120 std::string output = SaveBoardToString( board );
121
122 size_t fpStart = output.find( "(footprint" );
123 BOOST_REQUIRE( fpStart != std::string::npos );
124
125 size_t tentingPos = output.find( "(tenting", fpStart );
126 BOOST_CHECK_MESSAGE( tentingPos != std::string::npos,
127 "PTH pad with explicit tenting should have a (tenting) block" );
128}
129
130
134BOOST_AUTO_TEST_CASE( NpthDefaultTentingNotSerialized )
135{
136 BOARD board;
138
139 auto fp = std::make_unique<FOOTPRINT>( &board );
140 fp->SetPosition( VECTOR2I( 0, 0 ) );
141
142 auto* pad = new PAD( fp.get() );
143 pad->SetAttribute( PAD_ATTRIB::NPTH );
144 pad->SetLayerSet( PAD::UnplatedHoleMask() );
146 pad->SetSize( PADSTACK::ALL_LAYERS,
147 VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
148 pad->SetDrillSize( VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) ) );
149 pad->SetNumber( wxT( "" ) );
150 pad->SetPosition( VECTOR2I( pcbIUScale.mmToIU( 5 ), 0 ) );
151
152 BOOST_CHECK( !pad->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
153 BOOST_CHECK( !pad->Padstack().BackOuterLayers().has_solder_mask.has_value() );
154
155 fp->Add( pad );
156 board.Add( fp.release() );
157
158 std::string output = SaveBoardToString( board );
159
160 size_t fpStart = output.find( "(footprint" );
161 BOOST_REQUIRE( fpStart != std::string::npos );
162
163 size_t tentingPos = output.find( "(tenting", fpStart );
164 BOOST_CHECK_MESSAGE( tentingPos == std::string::npos,
165 "NPTH pad with default tenting should not have a (tenting) block" );
166}
167
168
172BOOST_AUTO_TEST_CASE( ViaDefaultTentingNotSerialized )
173{
174 BOARD board;
176
177 auto* via = new PCB_VIA( &board );
178 via->SetPosition( VECTOR2I( 0, 0 ) );
179 via->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.8 ) );
180 via->SetDrill( pcbIUScale.mmToIU( 0.4 ) );
181 via->SetViaType( VIATYPE::THROUGH );
182
183 BOOST_CHECK( !via->Padstack().FrontOuterLayers().has_solder_mask.has_value() );
184 BOOST_CHECK( !via->Padstack().BackOuterLayers().has_solder_mask.has_value() );
185
186 board.Add( via );
187
188 std::string output = SaveBoardToString( board );
189
190 size_t viaStart = output.find( "(via" );
191 BOOST_REQUIRE( viaStart != std::string::npos );
192
193 size_t tentingPos = output.find( "(tenting", viaStart );
194 BOOST_CHECK_MESSAGE( tentingPos == std::string::npos,
195 "Via with default tenting should not have a (tenting) block" );
196}
197
198
202BOOST_AUTO_TEST_CASE( ViaExplicitTentingSerialized )
203{
204 BOARD board;
206
207 auto* via = new PCB_VIA( &board );
208 via->SetPosition( VECTOR2I( 0, 0 ) );
209 via->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.8 ) );
210 via->SetDrill( pcbIUScale.mmToIU( 0.4 ) );
211 via->SetViaType( VIATYPE::THROUGH );
212
213 via->Padstack().FrontOuterLayers().has_solder_mask = false;
214 via->Padstack().BackOuterLayers().has_solder_mask = false;
215
216 board.Add( via );
217
218 std::string output = SaveBoardToString( board );
219
220 size_t viaStart = output.find( "(via" );
221 BOOST_REQUIRE( viaStart != std::string::npos );
222
223 size_t tentingPos = output.find( "(tenting", viaStart );
224 BOOST_CHECK_MESSAGE( tentingPos != std::string::npos,
225 "Via with explicit tenting should have a (tenting) block" );
226}
227
228
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
@ FPHOLDER
Definition board.h:364
General utilities for PCB file IO for QA programs.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1295
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:384
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
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:600
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
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.
nlohmann::json output
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683