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 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, force2;
38 
39  while( iter < aMaxIterations )
40  {
41  NODE::OPT_OBSTACLE obs = aNode->CheckColliding( &mv,
42  aSolidsOnly ? ITEM::SOLID_T : 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  bool col = CollideShapes( obs->m_item->Shape(), mv.Shape(), clearance, true, force2 );
57 
58  if( col ) {
59  totalForce += force2;
60  mv.SetPos( mv.Pos() + force2 );
61  }
62 
63  iter++;
64  }
65 
66  if( iter == aMaxIterations )
67  return false;
68 
69  aForce = totalForce;
70 
71  return true;
72 }
73 
74 
75 const SHAPE_LINE_CHAIN VIA::Hull( int aClearance, int aWalkaroundThickness ) const
76 {
77  int cl = ( aClearance + aWalkaroundThickness / 2 );
78 
79  return OctagonalHull( m_pos -
81  cl + 1, ( 2 * cl + m_diameter ) * 0.26 );
82 }
83 
84 
85 VIA* VIA::Clone() const
86 {
87  VIA* v = new VIA();
88 
89  v->SetNet( Net() );
90  v->SetLayers( Layers() );
91  v->m_pos = m_pos;
93  v->m_drill = m_drill;
94  v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
95  v->m_rank = m_rank;
96  v->m_marker = m_marker;
97  v->m_viaType = m_viaType;
98  v->m_parent = m_parent;
99 
100  return v;
101 }
102 
103 
104 OPT_BOX2I VIA::ChangedArea( const VIA* aOther ) const
105 {
106  if ( aOther->Pos() != Pos() )
107  {
108  BOX2I tmp = Shape()->BBox();
109  tmp.Merge( aOther->Shape()->BBox() );
110  return tmp;
111  }
112 
113  return OPT_BOX2I();
114 }
115 
117 {
118  VIA_HANDLE h;
119  h.pos = Pos();
120  h.layers = Layers();
121  h.net = Net();
122  h.valid = true;
123  return h;
124 }
125 
126 }
VIA()
Definition: pns_via.h:51
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:251
NODE.
Definition: pns_node.h:145
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:116
VIA * Clone() const override
Function Clone()
Definition: pns_via.cpp:85
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:258
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:104
const SHAPE * Shape() const override
Function Shape()
Definition: pns_via.h:148
const VECTOR2I & Pos() const
Definition: pns_via.h:100
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
int m_drill
Definition: pns_via.h:173
int m_marker
Definition: pns_item.h:257
void SetNet(int aNet)
Definition: pns_item.h:148
VECTOR2I m_pos
Definition: pns_via.h:174
int GetClearance(const ITEM *aA, const ITEM *aB) const
Returns the expected clearance between items a and b.
Definition: pns_node.cpp:97
int m_diameter
Definition: pns_via.h:172
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0) const override
Definition: pns_via.cpp:75
int Net() const
Definition: pns_item.h:149
SHAPE_CIRCLE m_shape
Definition: pns_via.h:175
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:385
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:152
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:105
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
SHAPE_LINE_CHAIN.
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
LAYER_RANGE layers
Definition: pns_via.h:44
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:524
VIATYPE m_viaType
Definition: pns_via.h:176
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.
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151