KiCad PCB EDA Suite
pns_solid.cpp
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2014 CERN
5  * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <math/vector2d.h>
23 
24 #include <geometry/shape.h>
26 #include <geometry/shape_rect.h>
27 #include <geometry/shape_circle.h>
28 #include <geometry/shape_simple.h>
30 
31 #include "pns_router.h"
32 #include "pns_solid.h"
33 #include "pns_utils.h"
34 
35 namespace PNS {
36 
37 static const SHAPE_LINE_CHAIN buildHullForPrimitiveShape( const SHAPE* aShape, int aClearance, int aWalkaroundThickness )
38 {
39  int cl = aClearance + ( aWalkaroundThickness + 1 )/ 2;
40 
41  switch( aShape->Type() )
42  {
43  case SH_RECT:
44  {
45  const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( aShape );
46  return OctagonalHull( rect->GetPosition(), rect->GetSize(), cl + 1, 0.2 * cl );
47  }
48 
49  case SH_CIRCLE:
50  {
51  const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( aShape );
52  int r = circle->GetRadius();
53  return OctagonalHull( circle->GetCenter() - VECTOR2I( r, r ), VECTOR2I( 2 * r, 2 * r ),
54  cl + 1, 0.52 * ( r + cl ) );
55  }
56 
57  case SH_SEGMENT:
58  {
59  const SHAPE_SEGMENT* seg = static_cast<const SHAPE_SEGMENT*>( aShape );
60  return SegmentHull( *seg, aClearance, aWalkaroundThickness );
61  }
62 
63  case SH_SIMPLE:
64  {
65  const SHAPE_SIMPLE* convex = static_cast<const SHAPE_SIMPLE*>( aShape );
66 
67  return ConvexHull( *convex, cl );
68  }
69  default:
70  {
71  wxLogError("Unsupported hull shape: %d", aShape->Type() );
72  break;
73  }
74  }
75 
76  return SHAPE_LINE_CHAIN();
77 }
78 
79 
80 const SHAPE_LINE_CHAIN SOLID::Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const
81 {
82  SHAPE* shape = m_shape;
83 
84  if( !ROUTER::GetInstance()->GetInterface()->IsOnLayer( this, aLayer ) )
85  {
88  if( !m_alternateShape )
89  return SHAPE_LINE_CHAIN();
90 
91  shape = m_alternateShape;
92  }
93 
94  if( shape->Type() == SH_COMPOUND )
95  {
96  auto cmpnd = static_cast<SHAPE_COMPOUND*>( shape );
97  if ( cmpnd->Shapes().size() == 1 )
98  {
99  return buildHullForPrimitiveShape( cmpnd->Shapes()[0], aClearance, aWalkaroundThickness );
100  }
101  else
102  {
103  // fixme - shouldn't happen but one day we should move TransformShapeWithClearanceToPolygon()
104  // to the Geometry Library
105  return SHAPE_LINE_CHAIN();
106  }
107  }
108  else
109  {
110  return buildHullForPrimitiveShape( shape, aClearance, aWalkaroundThickness );
111  }
112 
113  return SHAPE_LINE_CHAIN();
114 }
115 
116 
118 {
119  ITEM* solid = new SOLID( *this );
120  return solid;
121 }
122 
123 void SOLID::SetPos( const VECTOR2I& aCenter )
124 {
125  auto delta = aCenter - m_pos;
126 
127  if( m_shape )
128  m_shape->Move( delta );
129 
130  m_pos = aCenter;
131 }
132 
133 
134 }
set of polygons (with holes, etc.)
Definition: shape.h:49
ITEM.
Definition: pns_item.h:54
const SHAPE_LINE_CHAIN ConvexHull(const SHAPE_SIMPLE &aConvex, int aClearance)
Function ConvexHull()
Definition: pns_utils.cpp:160
SHAPE_SIMPLE.
Definition: shape_simple.h:43
int GetRadius() const
Definition: shape_circle.h:99
static const SHAPE_LINE_CHAIN buildHullForPrimitiveShape(const SHAPE *aShape, int aClearance, int aWalkaroundThickness)
Definition: pns_solid.cpp:37
void SetPos(const VECTOR2I &aCenter)
Definition: pns_solid.cpp:123
const VECTOR2I GetCenter() const
Definition: shape_circle.h:104
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
const SHAPE_LINE_CHAIN SegmentHull(const SHAPE_SEGMENT &aSeg, int aClearance, int aWalkaroundThickness)
Definition: pns_utils.cpp:112
SHAPE * m_shape
Definition: pns_solid.h:134
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:123
ITEM * Clone() const override
Function Clone()
Definition: pns_solid.cpp:117
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:113
const SHAPE_LINE_CHAIN OctagonalHull(const VECTOR2I &aP0, const VECTOR2I &aSize, int aClearance, int aChamfer)
Definition: pns_utils.cpp:35
SHAPE.
Definition: shape.h:122
line chain (polyline)
Definition: shape.h:46
SHAPE * m_alternateShape
Definition: pns_solid.h:135
SHAPE_LINE_CHAIN.
Definition: shape.h:43
virtual void Move(const VECTOR2I &aVector)=0
Push and Shove diff pair dimensions (gap) settings dialog.
circle
Definition: shape.h:47
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:98
static ROUTER * GetInstance()
Definition: pns_router.cpp:79
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_solid.cpp:80
axis-aligned rectangle
Definition: shape.h:44
VECTOR2I m_pos
Definition: pns_solid.h:133