KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_flashing.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>
29#include <pad.h>
30#include <memory>
31
32BOOST_AUTO_TEST_SUITE( PadFlashing )
33
34BOOST_AUTO_TEST_CASE( PadsInSameFootprintDoNotForceInnerLayerFlashing )
35{
36 BOARD board;
38
39 auto footprint = std::make_unique<FOOTPRINT>( &board );
40
41 auto net = new NETINFO_ITEM( &board, "P1", 1 );
42 board.Add( net );
43
44 auto pad1 = new PAD( footprint.get() );
45 auto pad2 = new PAD( footprint.get() );
46
47 const int diameter = pcbIUScale.mmToIU( 1.0 );
48 const int drill = pcbIUScale.mmToIU( 0.5 );
49
50 pad1->SetAttribute( PAD_ATTRIB::PTH );
51 pad2->SetAttribute( PAD_ATTRIB::PTH );
52 pad1->SetLayerSet( LSET::AllCuMask() );
53 pad2->SetLayerSet( LSET::AllCuMask() );
54 pad1->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
55 pad2->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
56 pad1->SetDrillSize( VECTOR2I( drill, drill ) );
57 pad2->SetDrillSize( VECTOR2I( drill, drill ) );
58 pad1->SetPosition( VECTOR2I( 0, 0 ) );
59 pad2->SetPosition( VECTOR2I( 0, 0 ) );
60 pad1->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
61 pad2->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
62 pad1->SetNet( net );
63 pad2->SetNet( net );
64
65 footprint->Add( pad1 );
66 footprint->Add( pad2 );
67 board.Add( footprint.release() );
68
69 board.BuildConnectivity();
70
71 BOOST_CHECK( pad1->FlashLayer( F_Cu ) );
72 BOOST_CHECK( pad2->FlashLayer( B_Cu ) );
73 BOOST_CHECK( !pad1->FlashLayer( In1_Cu ) );
74 BOOST_CHECK( !pad2->FlashLayer( In1_Cu ) );
75}
76
77BOOST_AUTO_TEST_CASE( PadsInDifferentFootprintsDoNotForceInnerLayerFlashing )
78{
79 BOARD board;
81
82 auto footprint1 = std::make_unique<FOOTPRINT>( &board );
83 auto footprint2 = std::make_unique<FOOTPRINT>( &board );
84
85 auto net = new NETINFO_ITEM( &board, "P1", 1 );
86 board.Add( net );
87
88 auto pad1 = new PAD( footprint1.get() );
89 auto pad2 = new PAD( footprint2.get() );
90
91 const int diameter = pcbIUScale.mmToIU( 1.0 );
92 const int drill = pcbIUScale.mmToIU( 0.5 );
93
94 pad1->SetAttribute( PAD_ATTRIB::PTH );
95 pad2->SetAttribute( PAD_ATTRIB::PTH );
96 pad1->SetLayerSet( LSET::AllCuMask() );
97 pad2->SetLayerSet( LSET::AllCuMask() );
98 pad1->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
99 pad2->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
100 pad1->SetDrillSize( VECTOR2I( drill, drill ) );
101 pad2->SetDrillSize( VECTOR2I( drill, drill ) );
102 pad1->SetPosition( VECTOR2I( 0, 0 ) );
103 pad2->SetPosition( VECTOR2I( 0, 0 ) );
104 pad1->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
105 pad2->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
106 pad1->SetNet( net );
107 pad2->SetNet( net );
108
109 footprint1->Add( pad1 );
110 footprint2->Add( pad2 );
111 board.Add( footprint1.release() );
112 board.Add( footprint2.release() );
113
114 board.BuildConnectivity();
115
116 BOOST_CHECK( pad1->FlashLayer( F_Cu ) );
117 BOOST_CHECK( pad2->FlashLayer( B_Cu ) );
118 BOOST_CHECK( !pad1->FlashLayer( In1_Cu ) );
119 BOOST_CHECK( !pad2->FlashLayer( In1_Cu ) );
120}
121
122
123BOOST_AUTO_TEST_CASE( TechLayersPullFromAppropriateSide )
124{
125 BOARD board;
127
128 auto footprint = std::make_unique<FOOTPRINT>( &board );
129
130 auto net = new NETINFO_ITEM( &board, "P1", 1 );
131 board.Add( net );
132
133 auto pad = new PAD( footprint.get() );
134
135 const int d1 = pcbIUScale.mmToIU( 1.0 );
136 const int d2 = pcbIUScale.mmToIU( 2.0 );
137 const int drill = pcbIUScale.mmToIU( 0.5 );
138
139 pad->SetAttribute( PAD_ATTRIB::PTH );
140 pad->SetLayerSet( LSET::AllCuMask() | LSET::AllBoardTechMask() );
141 pad->Padstack().SetMode( PADSTACK::MODE::CUSTOM );
142 pad->SetDrillSize( VECTOR2I( drill, drill ) );
143 pad->SetSize( F_Cu, VECTOR2I( d1, d1 ) );
144 pad->SetSize( B_Cu, VECTOR2I( d2, d2 ) );
145
146 pad->BuildEffectiveShapes();
147
148 auto shapes = pad->GetEffectiveShape( F_Mask );
149 BOOST_REQUIRE( dynamic_cast<SHAPE_COMPOUND*>( shapes.get() ) );
150 BOOST_REQUIRE( !dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Empty() );
151 SHAPE* subshape = dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Shapes()[0];
152 BOOST_REQUIRE( dynamic_cast<SHAPE_CIRCLE*>( subshape ) );
153 BOOST_CHECK_EQUAL( dynamic_cast<SHAPE_CIRCLE*>( subshape )->GetRadius(), d1 / 2 );
154
155 shapes = pad->GetEffectiveShape( B_Mask );
156 BOOST_REQUIRE( dynamic_cast<SHAPE_COMPOUND*>( shapes.get() ) );
157 BOOST_REQUIRE( !dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Empty() );
158 subshape = dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Shapes()[0];
159 BOOST_REQUIRE( dynamic_cast<SHAPE_CIRCLE*>( subshape ) );
160 BOOST_CHECK_EQUAL( dynamic_cast<SHAPE_CIRCLE*>( subshape )->GetRadius(), d2 / 2 );
161
162 BOOST_CHECK_EQUAL( pad->GetSize( F_Mask ).x, d1 );
163 BOOST_CHECK_EQUAL( pad->GetSize( B_Mask ).x, d2 );
164}
165
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
@ FPHOLDER
Definition board.h:315
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1237
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:335
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition board.cpp:195
static const LSET & AllBoardTechMask()
Return a mask holding board technical layers (no CU layer) on both side.
Definition lset.cpp:683
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:599
Handle the data for a net.
Definition netinfo.h:50
@ CUSTOM
Shapes can be defined on arbitrary layers.
Definition padstack.h:173
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
const std::vector< SHAPE * > & Shapes() const
bool Empty() const
An abstract shape on 2D plane.
Definition shape.h:126
@ B_Mask
Definition layer_ids.h:98
@ B_Cu
Definition layer_ids.h:65
@ F_Mask
Definition layer_ids.h:97
@ In1_Cu
Definition layer_ids.h:66
@ F_Cu
Definition layer_ids.h:64
@ PTH
Plated through hole pad.
Definition padstack.h:98
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(PadsInSameFootprintDoNotForceInnerLayerFlashing)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687