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 
29 namespace PNS {
30 
31 bool VIA::PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
32  bool aSolidsOnly, int aMaxIterations )
33 {
34  int iter = 0;
35  VIA mv( *this );
36  VECTOR2I force, totalForce, force2;
37 
38  while( iter < aMaxIterations )
39  {
40  NODE::OPT_OBSTACLE obs = aNode->CheckColliding( &mv,
41  aSolidsOnly ? ITEM::SOLID_T : ITEM::ANY_T );
42 
43  if( !obs )
44  break;
45 
46  int clearance = aNode->GetClearance( obs->m_item, &mv );
47 
48  if( iter > aMaxIterations / 2 )
49  {
50  VECTOR2I l = aDirection.Resize( m_diameter / 2 );
51  totalForce += l;
52  mv.SetPos( mv.Pos() + l );
53  }
54 
55  bool col = CollideShapes( obs->m_item->Shape(), mv.Shape(), clearance, true, force2 );
56 
57  if( col ) {
58  totalForce += force2;
59  mv.SetPos( mv.Pos() + force2 );
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 ) const
75 {
76  int cl = ( aClearance + aWalkaroundThickness / 2 );
77 
78  return OctagonalHull( m_pos -
80  cl + 1, ( 2 * cl + m_diameter ) * 0.26 );
81 }
82 
83 
84 VIA* VIA::Clone() const
85 {
86  VIA* v = new VIA();
87 
88  v->SetNet( Net() );
89  v->SetLayers( Layers() );
90  v->m_pos = m_pos;
92  v->m_drill = m_drill;
93  v->m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
94  v->m_rank = m_rank;
95  v->m_marker = m_marker;
96  v->m_viaType = m_viaType;
97 
98  return v;
99 }
100 
101 
102 OPT_BOX2I VIA::ChangedArea( const VIA* aOther ) const
103 {
104  if ( aOther->Pos() != Pos() )
105  {
106  BOX2I tmp = Shape()->BBox();
107  tmp.Merge( aOther->Shape()->BBox() );
108  return tmp;
109  }
110 
111  return OPT_BOX2I();
112 }
113 
114 }
VIA()
Definition: pns_via.h:39
Class NODE.
Definition: pns_node.h:137
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:207
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
VIATYPE_T m_viaType
Definition: pns_via.h:162
VIA * Clone() const override
Function Clone()
Definition: pns_via.cpp:84
bool PushoutForce(NODE *aNode, const VECTOR2I &aDirection, VECTOR2I &aForce, bool aSolidsOnly=true, int aMaxIterations=10)
Definition: pns_via.cpp:31
int m_rank
Definition: pns_item.h:355
const VECTOR2I & Pos() const
Definition: pns_via.h:88
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
const SHAPE * Shape() const override
Function Shape()
Definition: pns_via.h:136
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
int m_drill
Definition: pns_via.h:159
int m_marker
Definition: pns_item.h:354
void SetNet(int aNet)
Function SetNet()
Definition: pns_item.h:167
VECTOR2I m_pos
Definition: pns_via.h:160
int m_diameter
Definition: pns_via.h:158
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0) const override
Definition: pns_via.cpp:74
SHAPE_CIRCLE m_shape
Definition: pns_via.h:161
const SHAPE_LINE_CHAIN OctagonalHull(const VECTOR2I &aP0, const VECTOR2I &aSize, int aClearance, int aChamfer)
Various utility functions.
Definition: pns_utils.cpp:33
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:350
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:187
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:93
int GetClearance(const ITEM *aA, const ITEM *aB) const
Returns the expected clearance between items a and b.
Definition: pns_node.cpp:100
Class SHAPE_LINE_CHAIN.
OPT_OBSTACLE CheckColliding(const ITEM *aItem, int aKindMask=ITEM::ANY_T)
Function CheckColliding()
Definition: pns_node.cpp:427
int Net() const
Function Net()
Definition: pns_item.h:177
Push and Shove diff pair dimensions (gap) settings dialog.
boost::optional< BOX2I > OPT_BOX2I
Definition: box2.h:471
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:102