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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2020 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"
33 #include <fp_shape.h>
34 #include <footprint.h>
35 
36 
38  int aWidth ) const
39 {
40  if( aPad->GetShape() == PAD_SHAPE::CIRCLE ) // Draw a ring
41  {
42  TransformRingToPolygon( aCornerBuffer, aPad->ShapePos(), aPad->GetSize().x / 2,
43  aWidth, ARC_HIGH_DEF, ERROR_INSIDE );
44  return;
45  }
46 
47  // For other shapes, add outlines as thick segments in polygon buffer
48  const std::shared_ptr<SHAPE_POLY_SET>& corners = aPad->GetEffectivePolygon();
49  const SHAPE_LINE_CHAIN& path = corners->COutline( 0 );
50 
51  for( int ii = 0; ii < path.PointCount(); ++ii )
52  {
53  const VECTOR2I& a = path.CPoint( ii );
54  const VECTOR2I& b = path.CPoint( ii + 1 );
55 
56  TransformOvalToPolygon( aCornerBuffer, (wxPoint) a, (wxPoint) b, aWidth, ARC_HIGH_DEF,
57  ERROR_INSIDE );
58  }
59 }
60 
61 
63  SHAPE_POLY_SET& aCornerBuffer ) const
64 {
65  for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
66  {
67  if( item->Type() == PCB_FP_SHAPE_T )
68  {
69  FP_SHAPE* outline = (FP_SHAPE*) item;
70 
71  if( outline->GetLayer() == aLayer )
72  {
73  outline->TransformShapeWithClearanceToPolygon( aCornerBuffer, aLayer, 0,
74  ARC_HIGH_DEF, ERROR_INSIDE );
75  }
76  }
77  }
78 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void transformFPShapesToPolygon(const FOOTPRINT *aFootprint, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aCornerBuffer) const
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
wxPoint ShapePos() const
Definition: pad.cpp:673
Represent a set of closed polygons.
const wxSize & GetSize() const
Definition: pad.h:233
void buildPadOutlineAsPolygon(const PAD *aPad, SHAPE_POLY_SET &aCornerBuffer, int aWidth) const
PAD_SHAPE GetShape() const
Definition: pad.h:170
DRAWINGS & GraphicalItems()
Definition: footprint.h:171
Represent a polyline (an zero-thickness chain of connected line segments).
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
void TransformOvalToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aStart, const wxPoint &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon() const
Definition: pad.cpp:288
Definition: pad.h:57
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the draw segment to a closed polygon.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
void TransformRingToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.