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