KiCad PCB EDA Suite
create_layer_poly.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 (C) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
31#include "board_adapter.h"
34#include <fp_shape.h>
35#include <footprint.h>
36
37
38/*
39 * This is used to draw pad outlines on silk layers.
40 */
42 int aWidth ) const
43{
44 int maxError = m_board->GetDesignSettings().m_MaxError;
45
46 if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
47 {
48 TransformRingToPolygon( aBuffer, aPad->ShapePos(), aPad->GetSize().x / 2, aWidth, maxError,
50 return;
51 }
52
53 // For other shapes, add outlines as thick segments in polygon buffer
54 const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon();
55 const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
56
57 for( int ii = 0; ii < path.PointCount(); ++ii )
58 {
59 const VECTOR2I& a = path.CPoint( ii );
60 const VECTOR2I& b = path.CPoint( ii + 1 );
61
62 TransformOvalToPolygon( aBuffer, a, b, aWidth, maxError, ERROR_INSIDE );
63 }
64}
65
66
68 SHAPE_POLY_SET& aBuffer ) const
69{
70 int maxError = m_board->GetDesignSettings().m_MaxError;
71
72 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
73 {
74 if( item->Type() == PCB_FP_SHAPE_T )
75 {
76 FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
77
78 if( shape->GetLayer() == aLayer )
79 shape->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE );
80 }
81 else if( BaseType( item->Type() ) == PCB_DIMENSION_T )
82 {
83 PCB_DIMENSION_BASE* dimension = static_cast<PCB_DIMENSION_BASE*>( item );
84
85 if( dimension->GetLayer() == aLayer )
86 dimension->TransformShapeToPolygon( aBuffer, aLayer, 0, maxError, ERROR_INSIDE );
87 }
88 }
89}
void buildPadOutlineAsPolygon(const PAD *aPad, SHAPE_POLY_SET &aBuffer, int aWidth) const
void transformFPShapesToPolySet(const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aBuffer) const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:180
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:643
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
Definition: pad.h:59
VECTOR2I ShapePos() const
Definition: pad.cpp:757
PAD_SHAPE GetShape() const
Definition: pad.h:189
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon() const
Definition: pad.cpp:348
const VECTOR2I & GetSize() const
Definition: pad.h:252
Abstract dimension API.
Definition: pcb_dimension.h:96
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
Definition: pcb_shape.cpp:388
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void TransformRingToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ERROR_INSIDE
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition: typeinfo.h:253
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:105