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