KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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
28#include <math/box2.h>
29
30#include "pcb_track.h"
31
32#include "pns_item.h"
33#include "pns_linked_item.h"
34#include "pns_hole.h"
35
36namespace PNS {
37
38class NODE;
39
40// uniquely identifies a VIA within a NODE without using pointers. Used to
41// simplify (or complexifiy, depending on the point of view) the pointer management
42// in PNS::NODE. Sooner or later I'll have to fix it for good using smart pointers - twl
44{
45 VIA_HANDLE() : valid( false ) {};
47 valid( true ),
48 pos( aPos ),
49 layers (aLayers),
50 net (aNet ) {};
51
52 bool valid = false;
55 NET_HANDLE net = nullptr;
56};
57
58class VIA : public LINKED_ITEM
59{
60public:
61 enum class STACK_MODE
62 {
63 // The via is the same size on every layer
64 NORMAL,
65
66 // The via can have three different sizes -- note that in this context, front means
67 // m_layers.Start() and back means m_layers.End(), which does not align with KiCad in the
68 // case of blind/buried vias. Using this STACK_MODE only makes sense for vias that extend
69 // through the whole PCB
71
72 // The via can have a different size on each layer
73 CUSTOM
74 };
75
76 static constexpr int ALL_LAYERS = 0;
77 static constexpr int INNER_LAYERS = 1;
78
79 VIA() :
81 m_hole( nullptr )
82 {
84 m_diameters[0] = 2; // Dummy value
85 m_drill = 1; // Dummy value
86 m_viaType = VIATYPE::THROUGH;
87 m_isFree = false;
88 m_isVirtual = false;
90 }
91
92 VIA( const VECTOR2I& aPos, const PNS_LAYER_RANGE& aLayers, int aDiameter, int aDrill,
93 NET_HANDLE aNet = nullptr, VIATYPE aViaType = VIATYPE::THROUGH ) :
95 m_hole( nullptr )
96 {
97 SetNet( aNet );
98 SetLayers( aLayers );
99 m_pos = aPos;
101 m_diameters[0] = aDiameter;
102 m_drill = aDrill;
103 m_shapes[0] = SHAPE_CIRCLE( aPos, aDiameter / 2 );
105 m_viaType = aViaType;
106 m_isFree = false;
107 m_isVirtual = false;
108 }
109
110 VIA( const VIA& aB ) :
111 LINKED_ITEM( aB ),
112 m_hole( nullptr )
113 {
114 SetNet( aB.Net() );
115 SetLayers( aB.Layers() );
116 m_pos = aB.m_pos;
119
120 for( const auto& [layer, shape] : aB.m_shapes )
121 m_shapes[layer] = SHAPE_CIRCLE( m_pos, shape.GetRadius() );
122
123 m_drill = aB.m_drill;
125 m_marker = aB.m_marker;
126 m_rank = aB.m_rank;
127 m_viaType = aB.m_viaType;
128 m_isFree = aB.m_isFree;
130 }
131
132 virtual ~VIA()
133 {
134 if ( m_hole && m_hole->BelongsTo( this ) )
135 delete m_hole;
136 }
137
138 VIA& operator=( const VIA& aB )
139 {
140 SetNet( aB.Net() );
141 SetLayers( aB.Layers() );
142 m_pos = aB.m_pos;
145
146 for( const auto& [layer, shape] : aB.m_shapes )
147 m_shapes[layer] = SHAPE_CIRCLE( m_pos, shape.GetRadius() );
148
149 m_drill = aB.m_drill;
151 m_marker = aB.m_marker;
152 m_rank = aB.m_rank;
153 m_viaType = aB.m_viaType;
154 m_isFree = aB.m_isFree;
156 m_uid = aB.m_uid;
157 return *this;
158 }
159
160 static inline bool ClassOf( const ITEM* aItem )
161 {
162 return aItem && VIA_T == aItem->Kind();
163 }
164
165 STACK_MODE StackMode() const { return m_stackMode; }
166
167 void SetStackMode( STACK_MODE aStackMode );
168
169 int EffectiveLayer( int aLayer ) const;
170
171 std::vector<int> UniqueShapeLayers() const override;
172
173 bool HasUniqueShapeLayers() const override { return true; }
174
175 const VECTOR2I& Pos() const { return m_pos; }
176
177 void SetPos( const VECTOR2I& aPos )
178 {
179 m_pos = aPos;
180
181 for( auto& [layer, shape] : m_shapes )
182 shape.SetCenter( aPos );
183
184 if( m_hole )
185 m_hole->SetCenter( aPos );
186 }
187
188 VIATYPE ViaType() const { return m_viaType; }
189 void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
190
191 int Diameter( int aLayer ) const
192 {
193 int layer = EffectiveLayer( aLayer );
194 wxCHECK( m_diameters.contains( layer ), m_diameters.begin()->second );
195 return m_diameters.at( layer );
196 }
197
198 void SetDiameter( int aLayer, int aDiameter )
199 {
200 int layer = EffectiveLayer( aLayer );
201 m_diameters[layer] = aDiameter;
202
203 if( !m_shapes.contains( layer ) )
204 m_shapes[layer] = SHAPE_CIRCLE( m_pos, aDiameter / 2 );
205 else
206 m_shapes[layer].SetRadius( aDiameter / 2 );
207 }
208
209 bool PadstackMatches( const VIA& aOther ) const;
210
211 int Drill() const { return m_drill; }
212
213 void SetDrill( int aDrill )
214 {
215 m_drill = aDrill;
216
217 if( m_hole )
218 m_hole->SetRadius( m_drill / 2 );
219 }
220
221 bool IsFree() const { return m_isFree; }
222 void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
223
224 bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
225 int aCollisionMask = ITEM::ANY_T, int aMaxIterations = 10 );
226
227 bool PushoutForce( NODE* aNode, const ITEM* aOther, VECTOR2I& aForce );
228
229 const SHAPE* Shape( int aLayer ) const override
230 {
231 int layer = EffectiveLayer( aLayer );
232 wxCHECK( m_shapes.contains( layer ), nullptr );
233 return &m_shapes.at( layer );
234 }
235
236 VIA* Clone() const override;
237
238 const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
239 int aLayer = -1 ) const override;
240
241 virtual VECTOR2I Anchor( int n ) const override
242 {
243 return m_pos;
244 }
245
246 virtual int AnchorCount() const override
247 {
248 return 1;
249 }
250
251 OPT_BOX2I ChangedArea( const VIA* aOther ) const;
252
253 const VIA_HANDLE MakeHandle() const;
254
255 virtual void SetHole( HOLE* aHole ) override
256 {
257 if( m_hole && m_hole->BelongsTo( this ) )
258 delete m_hole;
259
260 m_hole = aHole;
261 m_hole->SetParentPadVia( this );
262 m_hole->SetOwner( this );
263 m_hole->SetLayers( m_layers ); // fixme: backdrill vias can have hole layer set different
264 // than copper layer set
265 }
266
267 virtual bool HasHole() const override { return true; }
268 virtual HOLE *Hole() const override { return m_hole; }
269
270 virtual const std::string Format() const override;
271
272private:
274
276 std::map<int, int> m_diameters;
277 std::map<int, SHAPE_CIRCLE> m_shapes;
278
284};
285
286
287class VVIA : public VIA
288{
289public:
290 VVIA( const VECTOR2I& aPos, int aLayer, int aDiameter, NET_HANDLE aNet ) :
291 VIA( aPos, PNS_LAYER_RANGE( aLayer, aLayer ), aDiameter, aDiameter / 2, aNet )
292 {
293 m_isVirtual = true;
294 }
295
296 bool HasHole() const override { return false; }
297};
298
299}
300
301#endif
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:926
void SetCenter(const VECTOR2I &aCenter)
Definition: pns_hole.cpp:111
void SetRadius(int aRadius)
Definition: pns_hole.cpp:118
void SetParentPadVia(ITEM *aParent)
Definition: pns_hole.h:71
static HOLE * MakeCircularHole(const VECTOR2I &pos, int radius, PNS_LAYER_RANGE aLayers)
Definition: pns_hole.cpp:131
Base class for PNS router board items.
Definition: pns_item.h:97
void SetLayers(const PNS_LAYER_RANGE &aLayers)
Definition: pns_item.h:200
bool m_isVirtual
Definition: pns_item.h:313
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:199
virtual NET_HANDLE Net() const
Definition: pns_item.h:197
PNS_LAYER_RANGE m_layers
Definition: pns_item.h:306
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:170
void SetNet(NET_HANDLE aNet)
Definition: pns_item.h:196
int m_marker
Definition: pns_item.h:310
int m_rank
Definition: pns_item.h:311
Keep the router "world" - i.e.
Definition: pns_node.h:231
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition: pns_item.h:76
bool BelongsTo(const ITEM_OWNER *aNode) const
Definition: pns_item.h:81
VIA()
Definition: pns_via.h:79
int Diameter(int aLayer) const
Definition: pns_via.h:191
void SetDiameter(int aLayer, int aDiameter)
Definition: pns_via.h:198
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:262
std::vector< int > UniqueShapeLayers() const override
Return a list of layers that have unique (potentially different) shapes.
Definition: pns_via.cpp:56
static bool ClassOf(const ITEM *aItem)
Definition: pns_via.h:160
int m_drill
Definition: pns_via.h:279
virtual VECTOR2I Anchor(int n) const override
Definition: pns_via.h:241
VIA(const VIA &aB)
Definition: pns_via.h:110
const VECTOR2I & Pos() const
Definition: pns_via.h:175
virtual void SetHole(HOLE *aHole) override
Definition: pns_via.h:255
std::map< int, int > m_diameters
May contain 1..n diameters depending on m_stackMode.
Definition: pns_via.h:276
VIA(const VECTOR2I &aPos, const PNS_LAYER_RANGE &aLayers, int aDiameter, int aDrill, NET_HANDLE aNet=nullptr, VIATYPE aViaType=VIATYPE::THROUGH)
Definition: pns_via.h:92
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:281
const SHAPE * Shape(int aLayer) const override
Return the geometrical shape of the item.
Definition: pns_via.h:229
VIATYPE ViaType() const
Definition: pns_via.h:188
virtual const std::string Format() const override
Definition: pns_via.cpp:292
bool PushoutForce(NODE *aNode, const VECTOR2I &aDirection, VECTOR2I &aForce, int aCollisionMask=ITEM::ANY_T, int aMaxIterations=10)
Definition: pns_via.cpp:125
virtual int AnchorCount() const override
Definition: pns_via.h:246
std::map< int, SHAPE_CIRCLE > m_shapes
Definition: pns_via.h:277
virtual HOLE * Hole() const override
Definition: pns_via.h:268
void SetIsFree(bool aIsFree)
Definition: pns_via.h:222
void SetViaType(VIATYPE aViaType)
Definition: pns_via.h:189
int EffectiveLayer(int aLayer) const
Definition: pns_via.cpp:33
int Drill() const
Definition: pns_via.h:211
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:177
VIA & operator=(const VIA &aB)
Definition: pns_via.h:138
void SetDrill(int aDrill)
Definition: pns_via.h:213
VIATYPE m_viaType
Definition: pns_via.h:281
virtual ~VIA()
Definition: pns_via.h:132
HOLE * m_hole
Definition: pns_via.h:283
bool PadstackMatches(const VIA &aOther) const
Definition: pns_via.cpp:90
bool IsFree() const
Definition: pns_via.h:221
VECTOR2I m_pos
Definition: pns_via.h:280
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:217
STACK_MODE
Definition: pns_via.h:62
static constexpr int ALL_LAYERS
Definition: pns_via.h:76
static constexpr int INNER_LAYERS
Definition: pns_via.h:77
void SetStackMode(STACK_MODE aStackMode)
Definition: pns_via.cpp:78
bool HasUniqueShapeLayers() const override
Definition: pns_via.h:173
bool m_isFree
Definition: pns_via.h:282
STACK_MODE StackMode() const
Definition: pns_via.h:165
STACK_MODE m_stackMode
Definition: pns_via.h:273
virtual bool HasHole() const override
Definition: pns_via.h:267
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:235
VVIA(const VECTOR2I &aPos, int aLayer, int aDiameter, NET_HANDLE aNet)
Definition: pns_via.h:290
bool HasHole() const override
Definition: pns_via.h:296
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
An abstract shape on 2D plane.
Definition: shape.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54
VIATYPE
Definition: pcb_track.h:66
VIA_HANDLE(VECTOR2I aPos, PNS_LAYER_RANGE aLayers, NET_HANDLE aNet)
Definition: pns_via.h:46
VECTOR2I pos
Definition: pns_via.h:53
NET_HANDLE net
Definition: pns_via.h:55
PNS_LAYER_RANGE layers
Definition: pns_via.h:54