KiCad PCB EDA Suite
pns_via.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 "pns_via.h"
23 #include "pns_node.h"
24 #include "pns_utils.h"
25 #include "pns_router.h"
26 
27 #include <geometry/shape_rect.h>
28 #include <math/box2.h>
29 
30 namespace PNS {
31 
32 bool VIA::PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
33  bool aSolidsOnly, int aMaxIterations )
34 {
35  int iter = 0;
36  VIA mv( *this );
37  VECTOR2I force, totalForce;
38 
39  while( iter < aMaxIterations )
40  {
41  NODE::OPT_OBSTACLE obs = aNode->CheckColliding( &mv, aSolidsOnly ? ITEM::SOLID_T
42  : ITEM::ANY_T );
43 
44  if( !obs )
45  break;
46 
47  int clearance = aNode->GetClearance( obs->m_item, &mv );
48 
49  if( iter > aMaxIterations / 2 )
50  {
51  VECTOR2I l = aDirection.Resize( m_diameter / 2 );
52  totalForce += l;
53  mv.SetPos( mv.Pos() + l );
54  }
55 
56  if( obs->m_item->Shape()->Collide( mv.Shape(), clearance, &force ) )
57  {
58  totalForce += force;
59  mv.SetPos( mv.Pos() + force );
60  }
61 
62  iter++;
63  }
64 
65  if( iter == aMaxIterations )
66  return false;
67 
68  aForce = totalForce;
69 
70  return true;
71 }
72 
73 
74 const SHAPE_LINE_CHAIN VIA::Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const
75 {
76  int cl = ( aClearance + aWalkaroundThickness / 2 );
77  int width = m_diameter;
78 
79  if( !ROUTER::GetInstance()->GetInterface()->IsFlashedOnLayer( this, aLayer ) )
80  width = m_drill;
81 
82  // Chamfer = width * ( 1 - sqrt(2)/2 ) for equilateral octagon
83  return OctagonalHull( m_pos - VECTOR2I( width / 2, width / 2 ),
84  VECTOR2I( width, width ),
85  cl + 1, ( 2 * cl + width ) * ( 1.0 - M_SQRT1_2 ) );
86 }
87 
88 
89 VIA* VIA::Clone() const
90 {
91  VIA* v = new VIA();
92 
93  v->SetNet( Net() );
94  v->SetLayers( Layers() );
95  v->m_pos = m_pos;
97  v->m_drill = m_drill;
98  v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
99  v->m_rank = m_rank;
100  v->m_marker = m_marker;
101  v->m_viaType = m_viaType;
102  v->m_parent = m_parent;
103  v->m_isFree = m_isFree;
105 
106  return v;
107 }
108 
109 
110 OPT_BOX2I VIA::ChangedArea( const VIA* aOther ) const
111 {
112  if ( aOther->Pos() != Pos() )
113  {
114  BOX2I tmp = Shape()->BBox();
115  tmp.Merge( aOther->Shape()->BBox() );
116  return tmp;
117  }
118 
119  return OPT_BOX2I();
120 }
121 
123 {
124  VIA_HANDLE h;
125  h.pos = Pos();
126  h.layers = Layers();
127  h.net = Net();
128  h.valid = true;
129  return h;
130 }
131 
132 }
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:122
VIA()
Definition: pns_via.h:51
Keep the router "world" - i.e.
Definition: pns_node.h:144
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:74
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:110
int m_rank
Definition: pns_item.h:251
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_via.h:128
const VECTOR2I & Pos() const
Definition: pns_via.h:99
virtual const BOX2I BBox(int aClearance=0) const =0
Compute a bounding box of the shape, with a margin of aClearance a collision.
int m_drill
Definition: pns_via.h:154
int m_marker
Definition: pns_item.h:250
void SetNet(int aNet)
Definition: pns_item.h:149
bool PushoutForce(NODE *aNode, const VECTOR2I &aDirection, VECTOR2I &aForce, bool aSolidsOnly=true, int aMaxIterations=10)
Definition: pns_via.cpp:32
VECTOR2I m_pos
Definition: pns_via.h:155
bool m_isFree
Definition: pns_via.h:159
BOARD_ITEM * m_parent
Definition: pns_item.h:244
int GetClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_node.cpp:101
int m_diameter
Definition: pns_via.h:153
int Net() const
Definition: pns_item.h:150
SHAPE_CIRCLE m_shape
Definition: pns_via.h:156
const SHAPE_LINE_CHAIN OctagonalHull(const VECTOR2I &aP0, const VECTOR2I &aSize, int aClearance, int aChamfer)
Definition: pns_utils.cpp:35
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:363
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:89
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:153
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:101
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404
virtual bool IsFlashedOnLayer(const PNS::ITEM *aItem, int aLayer) const =0
Represent a polyline (an zero-thickness chain of connected line segments).
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Check if the item collides with anything else in the world, and if found, returns the obstacle.
Definition: pns_node.cpp:450
LAYER_RANGE layers
Definition: pns_via.h:44
bool m_isVirtual
Definition: pns_item.h:253
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:509
VIATYPE m_viaType
Definition: pns_via.h:158
VECTOR2I pos
Definition: pns_via.h:43
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:147
Push and Shove diff pair dimensions (gap) settings dialog.
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:207
static ROUTER * GetInstance()
Definition: pns_router.cpp:78
const LAYER_RANGE & Layers() const
Definition: pns_item.h:152