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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <board.h>
23#include <footprint.h>
25#include <pad.h>
26#include <memory>
27
28BOOST_AUTO_TEST_SUITE( PadFlashing )
29
30BOOST_AUTO_TEST_CASE( PadsInSameFootprintDoNotForceInnerLayerFlashing )
31{
32 BOARD board;
34
35 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( &board );
36
37 NETINFO_ITEM* net = new NETINFO_ITEM( &board, "P1", 1 );
38 board.Add( net );
39
40 PAD* pad1 = new PAD( footprint.get() );
41 PAD* pad2 = new PAD( footprint.get() );
42
43 const int diameter = pcbIUScale.mmToIU( 1.0 );
44 const int drill = pcbIUScale.mmToIU( 0.5 );
45
52 pad1->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
53 pad2->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
54 pad1->SetDrillSize( VECTOR2I( drill, drill ) );
55 pad2->SetDrillSize( VECTOR2I( drill, drill ) );
56 pad1->SetPosition( VECTOR2I( 0, 0 ) );
57 pad2->SetPosition( VECTOR2I( 0, 0 ) );
60 pad1->SetNet( net );
61 pad2->SetNet( net );
62
63 footprint->Add( pad1 );
64 footprint->Add( pad2 );
65 board.Add( footprint.release() );
66
67 board.BuildConnectivity();
68
69 BOOST_CHECK( pad1->FlashLayer( F_Cu ) );
70 BOOST_CHECK( pad2->FlashLayer( B_Cu ) );
71 BOOST_CHECK( !pad1->FlashLayer( In1_Cu ) );
72 BOOST_CHECK( !pad2->FlashLayer( In1_Cu ) );
73}
74
75BOOST_AUTO_TEST_CASE( PadsInDifferentFootprintsDoNotForceInnerLayerFlashing )
76{
77 BOARD board;
79
80 std::unique_ptr<FOOTPRINT> footprint1 = std::make_unique<FOOTPRINT>( &board );
81 std::unique_ptr<FOOTPRINT> footprint2 = std::make_unique<FOOTPRINT>( &board );
82
83 NETINFO_ITEM* net = new NETINFO_ITEM( &board, "P1", 1 );
84 board.Add( net );
85
86 PAD* pad1 = new PAD( footprint1.get() );
87 PAD* pad2 = new PAD( footprint2.get() );
88
89 const int diameter = pcbIUScale.mmToIU( 1.0 );
90 const int drill = pcbIUScale.mmToIU( 0.5 );
91
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 ) );
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 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( &board );
129
130 NETINFO_ITEM* net = new NETINFO_ITEM( &board, "P1", 1 );
131 board.Add( net );
132
133 PAD* 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:121
@ FPHOLDER
Definition board.h:401
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1497
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:421
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:364
static const LSET & AllBoardTechMask()
Return a mask holding board technical layers (no CU layer) on both side.
Definition lset.cpp:679
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
Handle the data for a net.
Definition netinfo.h:50
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:170
@ CUSTOM
Shapes can be defined on arbitrary layers.
Definition padstack.h:172
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
Definition pad.h:61
void SetAttribute(PAD_ATTRIB aAttribute)
Definition pad.cpp:1639
bool FlashLayer(int aLayer, bool aOnlyCheckIfPermitted=false) const
Check to see whether the pad should be flashed on the specific layer.
Definition pad.cpp:677
void SetPadstackMode(PADSTACK::MODE aMode)
Definition pad.h:190
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition pad.h:889
void SetPosition(const VECTOR2I &aPos) override
Definition pad.cpp:235
void SetDrillSize(const VECTOR2I &aSize)
Definition pad.h:317
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.cpp:255
void SetLayerSet(const LSET &aLayers) override
Definition pad.cpp:1955
const std::vector< SHAPE * > & Shapes() const
bool Empty() const
An abstract shape on 2D plane.
Definition shape.h:124
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
@ PTH
Plated through hole pad.
Definition padstack.h:97
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:683