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, 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
25
27#include <board.h>
28#include <footprint.h>
29#include <pcb_shape.h>
31
41
42namespace
43{
45class HATCH_KNOCKOUT_SHAPE : public PCB_SHAPE
46{
47public:
49
50 SHAPE_POLY_SET CallGetHatchingKnockouts() const { return getHatchingKnockouts(); }
51};
52
53
55std::unique_ptr<BOARD> makeBoardWithCourtyard()
56{
57 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
58 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( board.get() );
59
60 const VECTOR2I size( pcbIUScale.mmToIU( 10 ), pcbIUScale.mmToIU( 10 ) );
61 const int width = pcbIUScale.mmToIU( 0.1 );
62
63 KI_TEST::DrawRect( *footprint, VECTOR2I( 0, 0 ), size, 0, width, F_CrtYd );
64
65 footprint->SetReference( "U1" );
66 footprint->SetPosition( VECTOR2I( 0, 0 ) );
67
68 board->Add( footprint.release() );
69 return board;
70}
71
72
74HATCH_KNOCKOUT_SHAPE* addHatchedRect( BOARD& aBoard, PCB_LAYER_ID aLayer )
75{
76 HATCH_KNOCKOUT_SHAPE* shape = new HATCH_KNOCKOUT_SHAPE( &aBoard, SHAPE_T::RECTANGLE );
77
78 shape->SetLayer( aLayer );
79 shape->SetStart( VECTOR2I( pcbIUScale.mmToIU( -20 ), pcbIUScale.mmToIU( -20 ) ) );
80 shape->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 20 ) ) );
81 shape->SetStroke( STROKE_PARAMS( pcbIUScale.mmToIU( 0.2 ), LINE_STYLE::SOLID ) );
82 shape->SetFillMode( FILL_T::HATCH );
83
84 aBoard.Add( shape );
85 return shape;
86}
87} // namespace
88
89
90BOOST_AUTO_TEST_SUITE( PcbShapeHatchKnockout )
91
92
96BOOST_AUTO_TEST_CASE( UserLayerIgnoresCourtyard )
97{
98 std::unique_ptr<BOARD> board = makeBoardWithCourtyard();
99 HATCH_KNOCKOUT_SHAPE* shape = addHatchedRect( *board, User_1 );
100
101 SHAPE_POLY_SET knockouts = shape->CallGetHatchingKnockouts();
102
103 BOOST_CHECK_EQUAL( knockouts.OutlineCount(), 0 );
104}
105
106
111BOOST_AUTO_TEST_CASE( CourtyardLayerKnocksOutCourtyard )
112{
113 std::unique_ptr<BOARD> board = makeBoardWithCourtyard();
114 HATCH_KNOCKOUT_SHAPE* shape = addHatchedRect( *board, F_CrtYd );
115
116 SHAPE_POLY_SET knockouts = shape->CallGetHatchingKnockouts();
117
118 BOOST_CHECK_GT( knockouts.OutlineCount(), 0 );
119 BOOST_CHECK_GT( knockouts.Area(), 0.0 );
120}
121
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:125
Construction utilities for PCB tests.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1247
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
Definition pcb_shape.cpp:54
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:51
@ HATCH
Definition eda_shape.h:68
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ F_CrtYd
Definition layer_ids.h:116
@ User_1
Definition layer_ids.h:124
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:687