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 auto footprint = std::make_unique<FOOTPRINT>( &board );
36
37 auto net = new NETINFO_ITEM( &board, "P1", 1 );
38 board.Add( net );
39
40 auto pad1 = new PAD( footprint.get() );
41 auto pad2 = new PAD( footprint.get() );
42
43 const int diameter = pcbIUScale.mmToIU( 1.0 );
44 const int drill = pcbIUScale.mmToIU( 0.5 );
45
46 pad1->SetAttribute( PAD_ATTRIB::PTH );
47 pad2->SetAttribute( PAD_ATTRIB::PTH );
48 pad1->SetLayerSet( LSET::AllCuMask() );
49 pad2->SetLayerSet( LSET::AllCuMask() );
50 pad1->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
51 pad2->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
52 pad1->SetDrillSize( VECTOR2I( drill, drill ) );
53 pad2->SetDrillSize( VECTOR2I( drill, drill ) );
54 pad1->SetPosition( VECTOR2I( 0, 0 ) );
55 pad2->SetPosition( VECTOR2I( 0, 0 ) );
56 pad1->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
57 pad2->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
58 pad1->SetNet( net );
59 pad2->SetNet( net );
60
61 footprint->Add( pad1 );
62 footprint->Add( pad2 );
63 board.Add( footprint.release() );
64
65 board.BuildConnectivity();
66
67 BOOST_CHECK( pad1->FlashLayer( F_Cu ) );
68 BOOST_CHECK( pad2->FlashLayer( B_Cu ) );
69 BOOST_CHECK( !pad1->FlashLayer( In1_Cu ) );
70 BOOST_CHECK( !pad2->FlashLayer( In1_Cu ) );
71}
72
73BOOST_AUTO_TEST_CASE( PadsInDifferentFootprintsDoNotForceInnerLayerFlashing )
74{
75 BOARD board;
77
78 auto footprint1 = std::make_unique<FOOTPRINT>( &board );
79 auto footprint2 = std::make_unique<FOOTPRINT>( &board );
80
81 auto net = new NETINFO_ITEM( &board, "P1", 1 );
82 board.Add( net );
83
84 auto pad1 = new PAD( footprint1.get() );
85 auto pad2 = new PAD( footprint2.get() );
86
87 const int diameter = pcbIUScale.mmToIU( 1.0 );
88 const int drill = pcbIUScale.mmToIU( 0.5 );
89
90 pad1->SetAttribute( PAD_ATTRIB::PTH );
91 pad2->SetAttribute( PAD_ATTRIB::PTH );
92 pad1->SetLayerSet( LSET::AllCuMask() );
93 pad2->SetLayerSet( LSET::AllCuMask() );
94 pad1->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
95 pad2->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( diameter, diameter ) );
96 pad1->SetDrillSize( VECTOR2I( drill, drill ) );
97 pad2->SetDrillSize( VECTOR2I( drill, drill ) );
98 pad1->SetPosition( VECTOR2I( 0, 0 ) );
99 pad2->SetPosition( VECTOR2I( 0, 0 ) );
100 pad1->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
101 pad2->SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
102 pad1->SetNet( net );
103 pad2->SetNet( net );
104
105 footprint1->Add( pad1 );
106 footprint2->Add( pad2 );
107 board.Add( footprint1.release() );
108 board.Add( footprint2.release() );
109
110 board.BuildConnectivity();
111
112 BOOST_CHECK( pad1->FlashLayer( F_Cu ) );
113 BOOST_CHECK( pad2->FlashLayer( B_Cu ) );
114 BOOST_CHECK( !pad1->FlashLayer( In1_Cu ) );
115 BOOST_CHECK( !pad2->FlashLayer( In1_Cu ) );
116}
117
118
119BOOST_AUTO_TEST_CASE( TechLayersPullFromAppropriateSide )
120{
121 BOARD board;
123
124 auto footprint = std::make_unique<FOOTPRINT>( &board );
125
126 auto net = new NETINFO_ITEM( &board, "P1", 1 );
127 board.Add( net );
128
129 auto pad = new PAD( footprint.get() );
130
131 const int d1 = pcbIUScale.mmToIU( 1.0 );
132 const int d2 = pcbIUScale.mmToIU( 2.0 );
133 const int drill = pcbIUScale.mmToIU( 0.5 );
134
135 pad->SetAttribute( PAD_ATTRIB::PTH );
136 pad->SetLayerSet( LSET::AllCuMask() | LSET::AllBoardTechMask() );
137 pad->Padstack().SetMode( PADSTACK::MODE::CUSTOM );
138 pad->SetDrillSize( VECTOR2I( drill, drill ) );
139 pad->SetSize( F_Cu, VECTOR2I( d1, d1 ) );
140 pad->SetSize( B_Cu, VECTOR2I( d2, d2 ) );
141
142 pad->BuildEffectiveShapes();
143
144 auto shapes = pad->GetEffectiveShape( F_Mask );
145 BOOST_REQUIRE( dynamic_cast<SHAPE_COMPOUND*>( shapes.get() ) );
146 BOOST_REQUIRE( !dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Empty() );
147 SHAPE* subshape = dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Shapes()[0];
148 BOOST_REQUIRE( dynamic_cast<SHAPE_CIRCLE*>( subshape ) );
149 BOOST_CHECK_EQUAL( dynamic_cast<SHAPE_CIRCLE*>( subshape )->GetRadius(), d1 / 2 );
150
151 shapes = pad->GetEffectiveShape( B_Mask );
152 BOOST_REQUIRE( dynamic_cast<SHAPE_COMPOUND*>( shapes.get() ) );
153 BOOST_REQUIRE( !dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Empty() );
154 subshape = dynamic_cast<SHAPE_COMPOUND*>( shapes.get() )->Shapes()[0];
155 BOOST_REQUIRE( dynamic_cast<SHAPE_CIRCLE*>( subshape ) );
156 BOOST_CHECK_EQUAL( dynamic_cast<SHAPE_CIRCLE*>( subshape )->GetRadius(), d2 / 2 );
157
158 BOOST_CHECK_EQUAL( pad->GetSize( F_Mask ).x, d1 );
159 BOOST_CHECK_EQUAL( pad->GetSize( B_Mask ).x, d2 );
160}
161
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
@ FPHOLDER
Definition board.h:364
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
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:201
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:46
@ 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: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: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:683