KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue25621_via_flashing_contact_layer.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>
25#include <footprint.h>
26#include <pad.h>
27#include <pcb_track.h>
28
29#include <memory>
30
31
32BOOST_AUTO_TEST_SUITE( ViaFlashingContactLayer )
33
34
35static void setupFourLayerBoard( BOARD& aBoard )
36{
37 aBoard.SetCopperLayerCount( 4 );
38 aBoard.SetEnabledLayers( aBoard.GetEnabledLayers() | LSET::AllCuMask( 4 ) );
39 aBoard.GetDesignSettings().SetCopperLayerCount( 4 );
40}
41
42
43static PCB_VIA* addThroughVia( BOARD& aBoard, NETINFO_ITEM* aNet, const VECTOR2I& aPos )
44{
45 PCB_VIA* via = new PCB_VIA( &aBoard );
46
47 via->SetViaType( VIATYPE::THROUGH );
48 via->SetPadstackMode( PADSTACK::MODE::NORMAL );
49 via->SetPosition( aPos );
50 via->SetLayerPair( F_Cu, B_Cu );
51 via->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.6 ) );
52 via->SetDrill( pcbIUScale.mmToIU( 0.3 ) );
53 via->Padstack().SetUnconnectedLayerMode( UNCONNECTED_LAYER_MODE::REMOVE_EXCEPT_START_AND_END );
54 via->SetNet( aNet );
55
56 aBoard.Add( via );
57 return via;
58}
59
60
61BOOST_AUTO_TEST_CASE( ViaTouchingPadOnFrontOnlyHasNoInnerRings )
62{
63 BOARD board;
64 setupFourLayerBoard( board );
65
66 NETINFO_ITEM* net = new NETINFO_ITEM( &board, "GND", 1 );
67 board.Add( net );
68
69 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( &board );
70 PAD* pad = new PAD( footprint.get() );
71
72 const int outerDiameter = pcbIUScale.mmToIU( 5.0 );
73 const int innerDiameter = pcbIUScale.mmToIU( 3.0 );
74 const int holeDiameter = pcbIUScale.mmToIU( 2.5 );
75
76 pad->SetAttribute( PAD_ATTRIB::PTH );
77 pad->SetLayerSet( LSET::AllCuMask() );
78 pad->SetPadstackMode( PADSTACK::MODE::FRONT_INNER_BACK );
79 pad->SetSize( F_Cu, VECTOR2I( outerDiameter, outerDiameter ) );
80 pad->SetSize( PADSTACK::INNER_LAYERS, VECTOR2I( innerDiameter, innerDiameter ) );
81 pad->SetSize( B_Cu, VECTOR2I( outerDiameter, outerDiameter ) );
82 pad->SetDrillSize( VECTOR2I( holeDiameter, holeDiameter ) );
83 pad->SetPosition( VECTOR2I( 0, 0 ) );
85 pad->SetNet( net );
86
87 footprint->Add( pad );
88 board.Add( footprint.release() );
89
90 // 2.2 mm puts the via inside the 5 mm front copper and 0.4 mm clear of the 3 mm inner copper
91 PCB_VIA* via = addThroughVia( board, net, VECTOR2I( pcbIUScale.mmToIU( 2.2 ), 0 ) );
92
93 board.BuildConnectivity();
94
95 BOOST_REQUIRE_MESSAGE( board.GetConnectivity()->IsConnectedOnLayer( via, F_Cu, { PCB_PAD_T } ),
96 "the via and the pad do not touch on F.Cu, so the rest of this test proves nothing" );
97
98 BOOST_CHECK_MESSAGE( via->FlashLayer( F_Cu ), "the via lost its ring on its start layer" );
99 BOOST_CHECK_MESSAGE( via->FlashLayer( B_Cu ), "the via lost its ring on its end layer" );
100 BOOST_CHECK_MESSAGE( pad->FlashLayer( F_Cu ), "the pad lost its front copper" );
101
102 BOOST_CHECK_MESSAGE( !via->FlashLayer( In1_Cu ), "the via has a ring on In1.Cu where it touches nothing" );
103 BOOST_CHECK_MESSAGE( !via->FlashLayer( In2_Cu ), "the via has a ring on In2.Cu where it touches nothing" );
104 BOOST_CHECK_MESSAGE( !pad->FlashLayer( In1_Cu ), "the pad has copper on In1.Cu where it touches nothing" );
105 BOOST_CHECK_MESSAGE( !pad->FlashLayer( In2_Cu ), "the pad has copper on In2.Cu where it touches nothing" );
106}
107
108
109BOOST_AUTO_TEST_CASE( ViaKeepsTheRingOnTheLayerItsTrackIsOn )
110{
111 BOARD board;
112 setupFourLayerBoard( board );
113
114 NETINFO_ITEM* net = new NETINFO_ITEM( &board, "GND", 1 );
115 board.Add( net );
116
117 PCB_VIA* via = addThroughVia( board, net, VECTOR2I( 0, 0 ) );
118
119 PCB_TRACK* track = new PCB_TRACK( &board );
120
121 track->SetLayer( In1_Cu );
122 track->SetStart( VECTOR2I( 0, 0 ) );
123 track->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 5.0 ), 0 ) );
124 track->SetWidth( pcbIUScale.mmToIU( 0.25 ) );
125 track->SetNet( net );
126 board.Add( track );
127
128 board.BuildConnectivity();
129
130 BOOST_REQUIRE_MESSAGE( board.GetConnectivity()->IsConnectedOnLayer( via, In1_Cu, { PCB_TRACE_T } ),
131 "the via and the track do not touch on In1.Cu, so this test proves nothing" );
132
133 BOOST_CHECK_MESSAGE( via->FlashLayer( In1_Cu ), "the via lost the ring on the layer its track is on" );
134 BOOST_CHECK_MESSAGE( !via->FlashLayer( In2_Cu ), "the via has a ring on In2.Cu where it touches nothing" );
135}
136
137
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1524
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:367
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:759
bool IsConnectedOnLayer(const BOARD_CONNECTED_ITEM *aItem, int aLayer, const std::initializer_list< KICAD_T > &aTypes={}) const
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
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
Definition padstack.h:171
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
Definition padstack.h:182
Definition pad.h:61
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:94
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:97
virtual void SetWidth(int aWidth)
Definition pcb_track.h:91
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
@ 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_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static PCB_VIA * addThroughVia(BOARD &aBoard, NETINFO_ITEM *aNet, const VECTOR2I &aPos)
BOOST_AUTO_TEST_CASE(ViaTouchingPadOnFrontOnlyHasNoInnerRings)
static void setupFourLayerBoard(BOARD &aBoard)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708