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-2016 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 
33 #include "cinfo3d_visu.h"
35 #include <class_edge_mod.h>
36 #include <class_module.h>
37 
38 
39 // This is the same function as in board_items_to_polygon_shape_transform.cpp
40 // but it adds the rect/trapezoid shapes with a different winding
42  SHAPE_POLY_SET& aCornerBuffer,
43  wxSize aInflateValue,
44  int aSegmentsPerCircle,
45  double aCorrectionFactor ) const
46 {
47  wxPoint corners[4];
48  wxPoint PadShapePos = aPad->ShapePos(); /* Note: for pad having a shape offset,
49  * the pad position is NOT the shape position */
50  switch( aPad->GetShape() )
51  {
52  case PAD_SHAPE_CIRCLE:
53  case PAD_SHAPE_OVAL:
55  aPad->TransformShapeWithClearanceToPolygon( aCornerBuffer, aInflateValue.x,
56  aSegmentsPerCircle, aCorrectionFactor );
57  break;
58 
60  case PAD_SHAPE_RECT:
61  {
62  SHAPE_LINE_CHAIN aLineChain;
63 
64  aPad->BuildPadPolygon( corners, aInflateValue, aPad->GetOrientation() );
65 
66  for( int ii = 0; ii < 4; ++ii )
67  {
68  corners[3-ii] += PadShapePos; // Shift origin to position
69  aLineChain.Append( corners[3-ii].x, corners[3-ii].y );
70  }
71 
72  aLineChain.SetClosed( true );
73 
74  aCornerBuffer.AddOutline( aLineChain );
75  }
76  break;
77 
78  default:
79  wxFAIL_MSG( wxT( "CINFO3D_VISU::buildPadShapePolygon: found a not implemented pad shape (new shape?)" ) );
80  break;
81  }
82 }
83 
84 
86  SHAPE_POLY_SET& aCornerBuffer,
87  int aWidth ) const
88 {
89  if( aPad->GetShape() == PAD_SHAPE_CIRCLE ) // Draw a ring
90  {
91  unsigned int nr_sides_per_circle = GetNrSegmentsCircle( ( aPad->GetSize().x / 2 +
92  aWidth / 2 ) * 2 );
93 
94  TransformRingToPolygon( aCornerBuffer, aPad->ShapePos(),
95  aPad->GetSize().x / 2, nr_sides_per_circle, aWidth );
96  return;
97  }
98 
99  // For other shapes, draw polygon outlines
100  SHAPE_POLY_SET corners;
101 
102  unsigned int nr_sides_per_circle = GetNrSegmentsCircle( glm::min( aPad->GetSize().x,
103  aPad->GetSize().y) );
104 
105  buildPadShapePolygon( aPad, corners, wxSize( 0, 0 ),
106  nr_sides_per_circle, GetCircleCorrectionFactor( nr_sides_per_circle ) );
107 
108  // Add outlines as thick segments in polygon buffer
109 
110  const SHAPE_LINE_CHAIN& path = corners.COutline( 0 );
111 
112  for( int ii = 0; ii < path.PointCount(); ++ii )
113  {
114  const VECTOR2I& a = path.CPoint( ii );
115  const VECTOR2I& b = path.CPoint( ii + 1 );
116 
118  wxPoint( a.x, a.y ),
119  wxPoint( b.x, b.y ),
120  nr_sides_per_circle,
121  aWidth );
122  }
123 }
124 
125 
126 // Based on the same function name in board_items_to_polyshape_transform.cpp
127 // It was implemented here to allow dynamic segments count per pad shape
129  SHAPE_POLY_SET& aCornerBuffer,
130  int aInflateValue,
131  bool aSkipNPTHPadsWihNoCopper ) const
132 {
133  const D_PAD* pad = aPads;
134 
135  wxSize margin;
136  for( ; pad != NULL; pad = pad->Next() )
137  {
138  if( !pad->IsOnLayer(aLayer) )
139  continue;
140 
141  // NPTH pads are not drawn on layers if the shape size and pos is the same
142  // as their hole:
143  if( aSkipNPTHPadsWihNoCopper && (pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED) )
144  {
145  if( (pad->GetDrillSize() == pad->GetSize()) &&
146  (pad->GetOffset() == wxPoint( 0, 0 )) )
147  {
148  switch( pad->GetShape() )
149  {
150  case PAD_SHAPE_CIRCLE:
151  if( pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
152  continue;
153  break;
154 
155  case PAD_SHAPE_OVAL:
156  if( pad->GetDrillShape() != PAD_DRILL_SHAPE_CIRCLE )
157  continue;
158  break;
159 
160  default:
161  break;
162  }
163  }
164  }
165 
166  switch( aLayer )
167  {
168  case F_Mask:
169  case B_Mask:
170  margin.x = margin.y = pad->GetSolderMaskMargin() + aInflateValue;
171  break;
172 
173  case F_Paste:
174  case B_Paste:
175  margin = pad->GetSolderPasteMargin();
176  margin.x += aInflateValue;
177  margin.y += aInflateValue;
178  break;
179 
180  default:
181  margin.x = margin.y = aInflateValue;
182  break;
183  }
184 
185  unsigned int aCircleToSegmentsCount = GetNrSegmentsCircle( pad->GetSize().x );
186  double aCorrectionFactor = GetCircleCorrectionFactor( aCircleToSegmentsCount );
187 
188  buildPadShapePolygon( pad, aCornerBuffer, margin,
189  aCircleToSegmentsCount, aCorrectionFactor );
190  }
191 }
192 
194  PCB_LAYER_ID aLayer,
195  SHAPE_POLY_SET& aCornerBuffer ) const
196 {
197  for( const EDA_ITEM* item = aModule->GraphicalItemsList();
198  item != NULL;
199  item = item->Next() )
200  {
201  switch( item->Type() )
202  {
203  case PCB_MODULE_EDGE_T:
204  {
205  EDGE_MODULE*outline = (EDGE_MODULE*) item;
206 
207  if( outline->GetLayer() != aLayer )
208  break;
209 
210  unsigned int aCircleToSegmentsCount =
212 
213  double aCorrectionFactor = GetCircleCorrectionFactor( aCircleToSegmentsCount );
214 
215  outline->TransformShapeWithClearanceToPolygon( aCornerBuffer,
216  0,
217  aCircleToSegmentsCount,
218  aCorrectionFactor );
219  }
220  break;
221 
222  default:
223  break;
224  }
225  }
226 }
void TransformRoundedEndsSegmentToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aStart, wxPoint aEnd, int aCircleToSegmentsCount, int aWidth)
Function TransformRoundedEndsSegmentToPolygon convert a segment with rounded ends to a polygon Conver...
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:238
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:63
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
int PointCount() const
Function PointCount()
Handles data related with the board to be visualized.
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:221
const wxSize & GetDrillSize() const
Definition: class_pad.h:188
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:166
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
BOARD_ITEM * Next() const
void SetClosed(bool aClosed)
Function SetClosed()
PCB_LAYER_ID
A quick note on layer IDs:
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const
Function TransformShapeWithClearanceToPolygon Convert the pad shape to a closed polygon Used in filli...
Class SHAPE_POLY_SET.
int GetSolderMaskMargin() const
Function GetSolderMaskMargin.
Definition: class_pad.cpp:537
int GetSizeMax() const
GetSizeMax.
D_PAD * Next() const
Definition: class_pad.h:106
const wxSize & GetSize() const
Definition: class_pad.h:182
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
unsigned int GetNrSegmentsCircle(float aDiameter3DU) const
GetNrSegmentsCircle.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
void TransformRingToPolygon(SHAPE_POLY_SET &aCornerBuffer, wxPoint aCentre, int aRadius, int aCircleToSegmentsCount, int aWidth)
Function TransformRingToPolygon Creates a polygon from a ring Convert arcs to multiple straight segme...
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void transformPadsShapesWithClearanceToPolygon(const DLIST< D_PAD > &aPads, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aCornerBuffer, int aInflateValue, bool aSkipNPTHPadsWihNoCopper) const
double GetCircleCorrectionFactor(int aNrSides) const
GetCircleCorrectionFactor - computes a angle correction factor used when creating circles...
Class SHAPE_LINE_CHAIN.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees, but soon degrees.
Definition: class_pad.h:214
wxSize GetSolderPasteMargin() const
Function GetSolderPasteMargin.
Definition: class_pad.cpp:570
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
wxPoint ShapePos() const
Definition: class_pad.cpp:418
DLIST< BOARD_ITEM > & GraphicalItemsList()
Definition: class_module.h:137
Module description (excepted pads)
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: class_pad.h:479
EDGE_MODULE class definition.
void buildPadShapePolygon(const D_PAD *aPad, SHAPE_POLY_SET &aCornerBuffer, wxSize aInflateValue, int aSegmentsPerCircle, double aCorrectionFactor) const
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
const wxPoint & GetOffset() const
Definition: class_pad.h:191
void transformGraphicModuleEdgeToPolygonSet(const MODULE *aModule, PCB_LAYER_ID aLayer, SHAPE_POLY_SET &aCornerBuffer) const
void buildPadShapeThickOutlineAsPolygon(const D_PAD *aPad, SHAPE_POLY_SET &aCornerBuffer, int aWidth) const
#define min(a, b)
Definition: auxiliary.h:85
virtual const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...