KiCad PCB EDA Suite
pns_via.h
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 #ifndef __PNS_VIA_H
23 #define __PNS_VIA_H
24 
26 #include <geometry/shape_circle.h>
27 #include <math/box2.h>
28 
29 #include "../class_track.h"
30 
31 #include "pns_item.h"
32 
33 namespace PNS {
34 
35 class NODE;
36 
37 // uniquely identifies a VIA within a NODE without using pointers. Used to
38 // simplify (or complexifiy, depending on the point of view) the pointer management
39 // in PNS::NODE. Sooner or later I'll have to fix it for good using smart pointers - twl
40 struct VIA_HANDLE
41 {
42  bool valid = false;
45  int net;
46 };
47 
48 class VIA : public ITEM
49 {
50 public:
51  VIA() :
52  ITEM( VIA_T )
53  {
54  m_diameter = 2; // Dummy value
55  m_drill = 0;
57  }
58 
59  VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill, int aNet = -1,
60  VIATYPE aViaType = VIATYPE::THROUGH )
61  : ITEM( VIA_T )
62  {
63  SetNet( aNet );
64  SetLayers( aLayers );
65  m_pos = aPos;
66  m_diameter = aDiameter;
67  m_drill = aDrill;
68  m_shape = SHAPE_CIRCLE( aPos, aDiameter / 2 );
69  m_viaType = aViaType;
70 
71  //If we're a through-board via, use all layers regardless of the set passed
72  if( aViaType == VIATYPE::THROUGH )
73  {
74  LAYER_RANGE allLayers( 0, MAX_CU_LAYERS - 1 );
75  SetLayers( allLayers );
76  }
77  }
78 
79 
80  VIA( const VIA& aB ) :
81  ITEM( aB )
82  {
83  SetNet( aB.Net() );
84  SetLayers( aB.Layers() );
85  m_pos = aB.m_pos;
88  m_marker = aB.m_marker;
89  m_rank = aB.m_rank;
90  m_drill = aB.m_drill;
91  m_viaType = aB.m_viaType;
92  }
93 
94  static inline bool ClassOf( const ITEM* aItem )
95  {
96  return aItem && VIA_T == aItem->Kind();
97  }
98 
99 
100  const VECTOR2I& Pos() const
101  {
102  return m_pos;
103  }
104 
105  void SetPos( const VECTOR2I& aPos )
106  {
107  m_pos = aPos;
108  m_shape.SetCenter( aPos );
109  }
110 
111  VIATYPE ViaType() const
112  {
113  return m_viaType;
114  }
115 
116  void SetViaType( VIATYPE aViaType )
117  {
118  m_viaType = aViaType;
119  }
120 
121  int Diameter() const
122  {
123  return m_diameter;
124  }
125 
126  void SetDiameter( int aDiameter )
127  {
128  m_diameter = aDiameter;
130  }
131 
132  int Drill() const
133  {
134  return m_drill;
135  }
136 
137  void SetDrill( int aDrill )
138  {
139  m_drill = aDrill;
140  }
141 
142  bool PushoutForce( NODE* aNode,
143  const VECTOR2I& aDirection,
144  VECTOR2I& aForce,
145  bool aSolidsOnly = true,
146  int aMaxIterations = 10 );
147 
148  const SHAPE* Shape() const override
149  {
150  return &m_shape;
151  }
152 
153  VIA* Clone() const override;
154 
155  const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0 ) const override;
156 
157  virtual VECTOR2I Anchor( int n ) const override
158  {
159  return m_pos;
160  }
161 
162  virtual int AnchorCount() const override
163  {
164  return 1;
165  }
166 
167  OPT_BOX2I ChangedArea( const VIA* aOther ) const;
168 
169  const VIA_HANDLE MakeHandle() const;
170 
171 private:
173  int m_drill;
177 };
178 
179 }
180 
181 #endif
ITEM.
Definition: pns_item.h:53
VIA(const VIA &aB)
Definition: pns_via.h:80
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:78
VIA()
Definition: pns_via.h:51
NODE.
Definition: pns_node.h:145
virtual int AnchorCount() const override
Definition: pns_via.h:162
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:116
VIATYPE ViaType() const
Definition: pns_via.h:111
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
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
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
static bool ClassOf(const ITEM *aItem)
Definition: pns_via.h:94
VECTOR2I m_pos
Definition: pns_via.h:174
void SetDiameter(int aDiameter)
Definition: pns_via.h:126
int Diameter() const
Definition: pns_via.h:121
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
VIATYPE
Definition: class_track.h:62
SHAPE.
Definition: shape.h:60
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:152
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:105
void SetRadius(int aRadius)
Definition: shape_circle.h:73
SHAPE_LINE_CHAIN.
LAYER_RANGE layers
Definition: pns_via.h:44
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:524
VIATYPE m_viaType
Definition: pns_via.h:176
void SetDrill(int aDrill)
Definition: pns_via.h:137
VECTOR2I pos
Definition: pns_via.h:43
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
int Drill() const
Definition: pns_via.h:132
Push and Shove diff pair dimensions (gap) settings dialog.
void SetViaType(VIATYPE aViaType)
Definition: pns_via.h:116
LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151
virtual VECTOR2I Anchor(int n) const override
Definition: pns_via.h:157
VIA(const VECTOR2I &aPos, const LAYER_RANGE &aLayers, int aDiameter, int aDrill, int aNet=-1, VIATYPE aViaType=VIATYPE::THROUGH)
Definition: pns_via.h:59