KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_shape_hatch_knockout.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
23#include <board.h>
24#include <footprint.h>
25#include <pcb_shape.h>
27
37
38namespace
39{
41class HATCH_KNOCKOUT_SHAPE : public PCB_SHAPE
42{
43public:
45
46 SHAPE_POLY_SET CallGetHatchingKnockouts() const { return getHatchingKnockouts(); }
47};
48
49
51std::unique_ptr<BOARD> makeBoardWithCourtyard()
52{
53 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
54 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( board.get() );
55
56 const VECTOR2I size( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) );
57 const int width = pcbIUScale.mmToIU( 0.1 );
58
59 KI_TEST::DrawRect( *footprint, VECTOR2I( 0, 0 ), size, 0, width, F_CrtYd );
60
61 footprint->SetReference( "U1" );
62 footprint->SetPosition( VECTOR2I( 0, 0 ) );
63
64 board->Add( footprint.release() );
65 return board;
66}
67
68
70HATCH_KNOCKOUT_SHAPE* addHatchedRect( BOARD& aBoard, PCB_LAYER_ID aLayer )
71{
72 HATCH_KNOCKOUT_SHAPE* shape = new HATCH_KNOCKOUT_SHAPE( &aBoard, SHAPE_T::RECTANGLE );
73
74 shape->SetLayer( aLayer );
75 shape->SetStart( VECTOR2I( pcbIUScale.mmToIU( -20 ), pcbIUScale.mmToIU( -20 ) ) );
76 shape->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 20 ) ) );
77 shape->SetStroke( STROKE_PARAMS( pcbIUScale.mmToIU( 0.2 ), LINE_STYLE::SOLID ) );
78 shape->SetFillMode( FILL_T::HATCH );
79
80 aBoard.Add( shape );
81 return shape;
82}
83} // namespace
84
85
86BOOST_AUTO_TEST_SUITE( PcbShapeHatchKnockout )
87
88
92BOOST_AUTO_TEST_CASE( UserLayerIgnoresCourtyard )
93{
94 std::unique_ptr<BOARD> board = makeBoardWithCourtyard();
95 HATCH_KNOCKOUT_SHAPE* shape = addHatchedRect( *board, User_1 );
96
97 SHAPE_POLY_SET knockouts = shape->CallGetHatchingKnockouts();
98
99 BOOST_CHECK_EQUAL( knockouts.OutlineCount(), 0 );
100}
101
102
107BOOST_AUTO_TEST_CASE( CourtyardLayerKnocksOutCourtyard )
108{
109 std::unique_ptr<BOARD> board = makeBoardWithCourtyard();
110 HATCH_KNOCKOUT_SHAPE* shape = addHatchedRect( *board, F_CrtYd );
111
112 SHAPE_POLY_SET knockouts = shape->CallGetHatchingKnockouts();
113
114 BOOST_CHECK_GT( knockouts.OutlineCount(), 0 );
115 BOOST_CHECK_GT( knockouts.Area(), 0.0 );
116}
117
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
Construction utilities for PCB tests.
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
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
Represent a set of closed polygons.
double Area()
Return the area of this poly set.
int OutlineCount() const
Return the number of outlines in the set.
Simple container to manage line stroke parameters.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:47
@ HATCH
Definition eda_shape.h:64
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ User_1
Definition layer_ids.h:120
void DrawRect(FOOTPRINT &aFootprint, const VECTOR2I &aPos, const VECTOR2I &aSize, int aRadius, int aWidth, PCB_LAYER_ID aLayer)
Draw a rectangle on a footprint.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(UserLayerIgnoresCourtyard)
A hatched shape on a User layer produces no knockouts, since the only same-layer item would be the fr...
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683