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-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 #ifndef __PNS_VIA_H
23 #define __PNS_VIA_H
24 
26 #include <geometry/shape_circle.h>
27 #include <math/box2.h>
28 
29 #include "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  m_isFree = false;
58  }
59 
60  VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill,
61  int aNet = -1, VIATYPE aViaType = VIATYPE::THROUGH ) :
62  ITEM( VIA_T )
63  {
64  SetNet( aNet );
65  SetLayers( aLayers );
66  m_pos = aPos;
67  m_diameter = aDiameter;
68  m_drill = aDrill;
69  m_shape = SHAPE_CIRCLE( aPos, aDiameter / 2 );
70  m_hole = SHAPE_CIRCLE( m_pos, aDrill / 2 );
71  m_viaType = aViaType;
72  m_isFree = false;
73  }
74 
75  VIA( const VIA& aB ) :
76  ITEM( aB )
77  {
78  SetNet( aB.Net() );
79  SetLayers( aB.Layers() );
80  m_pos = aB.m_pos;
83  m_hole = SHAPE_CIRCLE( m_pos, aB.m_drill / 2 );
84  m_marker = aB.m_marker;
85  m_rank = aB.m_rank;
86  m_drill = aB.m_drill;
87  m_viaType = aB.m_viaType;
88  m_isFree = aB.m_isFree;
89  }
90 
91  static inline bool ClassOf( const ITEM* aItem )
92  {
93  return aItem && VIA_T == aItem->Kind();
94  }
95 
96  const VECTOR2I& Pos() const { return m_pos; }
97 
98  void SetPos( const VECTOR2I& aPos )
99  {
100  m_pos = aPos;
101  m_shape.SetCenter( aPos );
102  }
103 
104  VIATYPE ViaType() const { return m_viaType; }
105  void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
106 
107  int Diameter() const { return m_diameter; }
108 
109  void SetDiameter( int aDiameter )
110  {
111  m_diameter = aDiameter;
113  }
114 
115  int Drill() const { return m_drill; }
116  void SetDrill( int aDrill ) { m_drill = aDrill; }
117 
118  bool IsFree() const { return m_isFree; }
119  void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
120 
121  bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
122  bool aSolidsOnly = true, int aMaxIterations = 10 );
123 
124  const SHAPE* Shape() const override { return &m_shape; }
125 
126  const SHAPE_CIRCLE* Hole() const override { return &m_hole; }
127  void SetHole( const SHAPE_CIRCLE& aHole ) { m_hole = aHole; }
128 
129  VIA* Clone() const override;
130 
131  const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
132  int aLayer = -1 ) const override;
133 
134  virtual VECTOR2I Anchor( int n ) const override
135  {
136  return m_pos;
137  }
138 
139  virtual int AnchorCount() const override
140  {
141  return 1;
142  }
143 
144  OPT_BOX2I ChangedArea( const VIA* aOther ) const;
145 
146  const VIA_HANDLE MakeHandle() const;
147 
148 private:
150  int m_drill;
155  bool m_isFree;
156 };
157 
158 }
159 
160 #endif
Base class for PNS router board items.
Definition: pns_item.h:55
VIA(const VIA &aB)
Definition: pns_via.h:75
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:97
VIA()
Definition: pns_via.h:51
Keep the router "world" - i.e.
Definition: pns_node.h:149
virtual int AnchorCount() const override
Definition: pns_via.h:139
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:120
VIATYPE ViaType() const
Definition: pns_via.h:104
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
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:124
const VECTOR2I & Pos() const
Definition: pns_via.h:96
int m_drill
Definition: pns_via.h:150
SHAPE_CIRCLE m_hole
Definition: pns_via.h:153
int m_marker
Definition: pns_item.h:243
void SetNet(int aNet)
Definition: pns_item.h:147
static bool ClassOf(const ITEM *aItem)
Definition: pns_via.h:91
VECTOR2I m_pos
Definition: pns_via.h:151
void SetDiameter(int aDiameter)
Definition: pns_via.h:109
bool m_isFree
Definition: pns_via.h:155
int Diameter() const
Definition: pns_via.h:107
int m_diameter
Definition: pns_via.h:149
int Net() const
Definition: pns_item.h:148
void SetIsFree(bool aIsFree)
Definition: pns_via.h:119
SHAPE_CIRCLE m_shape
Definition: pns_via.h:152
const SHAPE_CIRCLE * Hole() const override
Definition: pns_via.h:126
An abstract shape on 2D plane.
Definition: shape.h:116
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:151
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:98
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:74
void SetRadius(int aRadius)
Definition: shape_circle.h:92
SHAPE_LINE_CHAIN.
LAYER_RANGE layers
Definition: pns_via.h:44
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:525
VIATYPE m_viaType
Definition: pns_via.h:154
void SetDrill(int aDrill)
Definition: pns_via.h:116
VECTOR2I pos
Definition: pns_via.h:43
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:126
VIATYPE
Definition: track.h:68
void SetHole(const SHAPE_CIRCLE &aHole)
Definition: pns_via.h:127
int Drill() const
Definition: pns_via.h:115
Push and Shove diff pair dimensions (gap) settings dialog.
void SetViaType(VIATYPE aViaType)
Definition: pns_via.h:105
bool IsFree() const
Definition: pns_via.h:118
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150
virtual VECTOR2I Anchor(int n) const override
Definition: pns_via.h:134
VIA(const VECTOR2I &aPos, const LAYER_RANGE &aLayers, int aDiameter, int aDrill, int aNet=-1, VIATYPE aViaType=VIATYPE::THROUGH)
Definition: pns_via.h:60