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  return OctagonalHull( m_pos -
83  VECTOR2I( width / 2, width / 2 ), VECTOR2I( width, width ),
84  cl + 1, ( 2 * cl + width ) * 0.26 );
85 }
86 
87 
88 VIA* VIA::Clone() const
89 {
90  VIA* v = new VIA();
91 
92  v->SetNet( Net() );
93  v->SetLayers( Layers() );
94  v->m_pos = m_pos;
96  v->m_drill = m_drill;
97  v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
98  v->m_rank = m_rank;
99  v->m_marker = m_marker;
100  v->m_viaType = m_viaType;
101  v->m_parent = m_parent;
102  v->m_isFree = m_isFree;
103 
104  return v;
105 }
106 
107 
108 OPT_BOX2I VIA::ChangedArea( const VIA* aOther ) const
109 {
110  if ( aOther->Pos() != Pos() )
111  {
112  BOX2I tmp = Shape()->BBox();
113  tmp.Merge( aOther->Shape()->BBox() );
114  return tmp;
115  }
116 
117  return OPT_BOX2I();
118 }
119 
121 {
122  VIA_HANDLE h;
123  h.pos = Pos();
124  h.layers = Layers();
125  h.net = Net();
126  h.valid = true;
127  return h;
128 }
129 
130 }
VIA()
Definition: pns_via.h:51
Keep the router "world" - i.e.
Definition: pns_node.h:145
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:120
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:88
bool PushoutForce(NODE *aNode, const VECTOR2I &aDirection, VECTOR2I &aForce, bool aSolidsOnly=true, int aMaxIterations=10)
Definition: pns_via.cpp:32
int m_rank
Definition: pns_item.h:244
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:108
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_via.h:125
const VECTOR2I & Pos() const
Definition: pns_via.h:96
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:151
int m_marker
Definition: pns_item.h:243
void SetNet(int aNet)
Definition: pns_item.h:147
VECTOR2I m_pos
Definition: pns_via.h:152
bool m_isFree
Definition: pns_via.h:156
BOARD_ITEM * m_parent
Definition: pns_item.h:237
int GetClearance(const ITEM *aA, const ITEM *aB) const
Definition: pns_node.cpp:97
int m_diameter
Definition: pns_via.h:150
int Net() const
Definition: pns_item.h:148
SHAPE_CIRCLE m_shape
Definition: pns_via.h:153
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)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
Definition: box2.h:386
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:151
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:98
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
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:74
SHAPE_LINE_CHAIN.
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:425
LAYER_RANGE layers
Definition: pns_via.h:44
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:525
VIATYPE m_viaType
Definition: pns_via.h:155
VECTOR2I pos
Definition: pns_via.h:43
OPT< OBSTACLE > OPT_OBSTACLE
Definition: pns_node.h:148
Push and Shove diff pair dimensions (gap) settings dialog.
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:210
static ROUTER * GetInstance()
Definition: pns_router.cpp:79
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150