KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_zone.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
26
27#include <board.h>
28#include <footprint.h>
29#include <zone.h>
30
31
36
37
38BOOST_FIXTURE_TEST_SUITE( Zone, ZONE_TEST_FIXTURE )
39
41{
42 ZONE zone( &m_board );
43
44 zone.SetLayer( F_Cu );
45
46 BOOST_TEST( zone.GetLayer() == F_Cu );
47 BOOST_TEST( zone.GetLayer() == zone.GetFirstLayer() );
48
49 BOOST_TEST( zone.IsOnCopperLayer() == true );
50}
51
52BOOST_AUTO_TEST_CASE( MultipleLayers )
53{
54 ZONE zone( &m_board );
55
56 zone.SetLayerSet( { F_Cu, B_Cu } );
57
58 // There is no "the" layer in a multi-layer zone
60 // ... but there is a first layer
61 BOOST_TEST( zone.GetFirstLayer() == F_Cu );
62
63 BOOST_TEST( zone.IsOnCopperLayer() == true );
64}
65
72BOOST_AUTO_TEST_CASE( RescuedLayers )
73{
74 ZONE zone( &m_board );
75
76 zone.SetLayer( Rescue );
77
78 BOOST_TEST( zone.GetLayer() == Rescue );
79 BOOST_TEST( zone.GetLayer() == zone.GetFirstLayer() );
80
81 BOOST_TEST( zone.IsOnCopperLayer() == false );
82}
83
91BOOST_AUTO_TEST_CASE( RuleAreaInnerLayersExpandMode )
92{
93 FOOTPRINT footprint( &m_board );
95
96 ZONE* ruleArea = new ZONE( &footprint );
97 ruleArea->SetIsRuleArea( true );
98 ruleArea->SetLayerSet( LSET::InternalCuMask() );
99 footprint.Add( ruleArea );
100
101 // Collect all layers used by the footprint (mirrors GetAllUsedFootprintLayers
102 // from dialog_footprint_properties_fp_editor.cpp)
103 LSET usedLayers;
104
105 footprint.RunOnChildren(
106 [&]( BOARD_ITEM* aItem )
107 {
108 if( aItem->Type() == PCB_ZONE_T )
109 usedLayers |= static_cast<ZONE*>( aItem )->GetLayerSet();
110 else
111 usedLayers.set( aItem->GetLayer() );
112 },
114
115 // In EXPAND_INNER_LAYERS mode, F_Cu, B_Cu and all inner copper layers
116 // are valid, along with tech, user, and user-defined layers.
117 LSET allowedLayers = LSET{ F_Cu, B_Cu } | LSET::InternalCuMask();
118 allowedLayers |= LSET::UserDefinedLayersMask( 4 );
119
120 usedLayers &= ~allowedLayers;
121 usedLayers &= ~LSET::AllTechMask();
122 usedLayers &= ~LSET::UserMask();
123
124 BOOST_TEST( usedLayers.none() );
125}
126
133BOOST_AUTO_TEST_CASE( EmptyZoneGetPosition )
134{
135 ZONE zone( &m_board );
136 zone.SetLayer( F_Cu );
137
138 BOOST_TEST( zone.GetNumCorners() == 0 );
139 BOOST_CHECK_NO_THROW( zone.GetPosition() );
140 BOOST_TEST( zone.GetPosition() == VECTOR2I( 0, 0 ) );
141}
142
BASE_SET & set(size_t pos)
Definition base_set.h:116
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:237
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
void SetStackupMode(FOOTPRINT_STACKUP aMode)
Set the stackup mode for this footprint.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET UserDefinedLayersMask(int aUserDefinedLayerCount=MAX_USER_DEFINED_LAYERS)
Return a mask with the requested number of user defined layers.
Definition lset.cpp:704
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:577
Handle a list of polygons defining a copper zone.
Definition zone.h:73
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition zone.cpp:501
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:550
void SetIsRuleArea(bool aEnable)
Definition zone.h:720
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:556
VECTOR2I GetPosition() const override
Definition zone.cpp:492
bool IsOnCopperLayer() const override
Definition zone.cpp:543
PCB_LAYER_ID GetFirstLayer() const
Definition zone.cpp:523
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition zone.h:524
@ RECURSE
Definition eda_item.h:52
@ EXPAND_INNER_LAYERS
The 'normal' stackup handling, where there is a single inner layer (In1) and rule areas using it expa...
Definition footprint.h:99
@ B_Cu
Definition layer_ids.h:65
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ Rescue
Definition layer_ids.h:121
@ F_Cu
Definition layer_ids.h:64
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_TEST(contains==c.ExpectedContains)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SingleLayer)
Definition test_zone.cpp:40
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:108
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695