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 The 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#include <optional>
30
31#include "pcb_track.h"
32
33#include "pns_item.h"
34#include "pns_linked_item.h"
35#include "pns_hole.h"
36
37namespace PNS {
38
39class NODE;
40
41// uniquely identifies a VIA within a NODE without using pointers. Used to
42// simplify (or complexifiy, depending on the point of view) the pointer management
43// in PNS::NODE. Sooner or later I'll have to fix it for good using smart pointers - twl
45{
46 VIA_HANDLE() : valid( false ) {};
48 valid( true ),
49 pos( aPos ),
50 layers (aLayers),
51 net (aNet ) {};
52
53 bool valid = false;
56 NET_HANDLE net = nullptr;
57};
58
59class VIA : public LINKED_ITEM
60{
61public:
62 enum class STACK_MODE
63 {
64 // The via is the same size on every layer
66
67 // The via can have three different sizes -- note that in this context, front means
68 // m_layers.Start() and back means m_layers.End(), which does not align with KiCad in the
69 // case of blind/buried vias. Using this STACK_MODE only makes sense for vias that extend
70 // through the whole PCB
72
73 // The via can have a different size on each layer
75 };
76
77 static constexpr int ALL_LAYERS = 0;
78 static constexpr int INNER_LAYERS = 1;
79
80 VIA() :
82 m_hole( nullptr )
83 {
85 m_diameters[0] = 2; // Dummy value
86 m_drill = 1; // Dummy value
89 m_isFree = false;
90 m_isVirtual = false;
93 m_secondaryDrill.reset();
97 }
98
99 VIA( const VECTOR2I& aPos, const PNS_LAYER_RANGE& aLayers, int aDiameter, int aDrill,
100 NET_HANDLE aNet = nullptr, VIATYPE aViaType = VIATYPE::THROUGH ) :
102 m_hole( nullptr )
103 {
104 SetNet( aNet );
105 SetLayers( aLayers );
106 m_pos = aPos;
108 m_diameters[0] = aDiameter;
109 m_drill = aDrill;
110 m_shapes[0] = SHAPE_CIRCLE( aPos, aDiameter / 2 );
111 SetHoleLayers( aLayers );
112 m_secondaryHoleLayers.reset();
113 m_secondaryDrill.reset();
117 m_viaType = aViaType;
119 m_isFree = false;
120 m_isVirtual = false;
121 }
122
123 VIA( const VIA& aB ) :
124 LINKED_ITEM( aB ),
125 m_hole( nullptr )
126 {
127 SetNet( aB.Net() );
128 SetLayers( aB.Layers() );
129 m_pos = aB.m_pos;
132
133 for( const auto& [layer, shape] : aB.m_shapes )
134 m_shapes[layer] = SHAPE_CIRCLE( m_pos, shape.GetRadius() );
135
136 m_drill = aB.m_drill;
143 m_marker = aB.m_marker;
144 m_rank = aB.m_rank;
145 m_viaType = aB.m_viaType;
147 m_isFree = aB.m_isFree;
149 }
150
151 virtual ~VIA()
152 {
153 if ( m_hole && m_hole->BelongsTo( this ) )
154 delete m_hole;
155 }
156
157 VIA& operator=( const VIA& aB )
158 {
159 SetParent( aB.Parent() );
161
162 SetNet( aB.Net() );
163 SetLayers( aB.Layers() );
164 m_movable = aB.m_movable;
165 m_pos = aB.m_pos;
168
169 for( const auto& [layer, shape] : aB.m_shapes )
170 m_shapes[layer] = SHAPE_CIRCLE( m_pos, shape.GetRadius() );
171
172 m_drill = aB.m_drill;
179 m_marker = aB.m_marker;
180 m_rank = aB.m_rank;
182 m_viaType = aB.m_viaType;
184 m_isFree = aB.m_isFree;
186 m_uid = aB.m_uid;
187 return *this;
188 }
189
190 static inline bool ClassOf( const ITEM* aItem )
191 {
192 return aItem && VIA_T == aItem->Kind();
193 }
194
195 STACK_MODE StackMode() const { return m_stackMode; }
196
197 void SetStackMode( STACK_MODE aStackMode );
198
199 int EffectiveLayer( int aLayer ) const;
200
201 std::vector<int> UniqueShapeLayers() const override;
202
203 bool HasUniqueShapeLayers() const override { return true; }
204
205 const VECTOR2I& Pos() const { return m_pos; }
206
207 void SetPos( const VECTOR2I& aPos )
208 {
209 m_pos = aPos;
210
211 for( auto& [layer, shape] : m_shapes )
212 shape.SetCenter( aPos );
213
214 if( m_hole )
215 m_hole->SetCenter( aPos );
216 }
217
218 VIATYPE ViaType() const { return m_viaType; }
219 void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
220
223
224 bool ConnectsLayer( int aLayer ) const;
225
226 int Diameter( int aLayer ) const
227 {
228 int layer = EffectiveLayer( aLayer );
229 wxCHECK( m_diameters.contains( layer ), m_diameters.begin()->second );
230 return m_diameters.at( layer );
231 }
232
233 void SetDiameter( int aLayer, int aDiameter )
234 {
235 int layer = EffectiveLayer( aLayer );
236 m_diameters[layer] = aDiameter;
237
238 if( !m_shapes.contains( layer ) )
239 m_shapes[layer] = SHAPE_CIRCLE( m_pos, aDiameter / 2 );
240 else
241 m_shapes[layer].SetRadius( aDiameter / 2 );
242 }
243
244 bool PadstackMatches( const VIA& aOther ) const;
245
246 int Drill() const { return m_drill; }
247
248 void SetDrill( int aDrill )
249 {
250 m_drill = aDrill;
251
252 if( m_hole )
253 m_hole->SetRadius( m_drill / 2 );
254 }
255
256 void SetHoleLayers( const PNS_LAYER_RANGE& aLayers );
257 const PNS_LAYER_RANGE& HoleLayers() const { return m_holeLayers; }
258
259 void SetHolePostMachining( const std::optional<PAD_DRILL_POST_MACHINING_MODE>& aPostMachining )
260 {
261 m_primaryPostMachining = aPostMachining;
262 }
263
264 std::optional<PAD_DRILL_POST_MACHINING_MODE> HolePostMachining() const { return m_primaryPostMachining; }
265
266 void SetSecondaryDrill( const std::optional<int>& aDrill )
267 {
268 m_secondaryDrill = aDrill;
269 }
270
271 std::optional<int> SecondaryDrill() const { return m_secondaryDrill; }
272
273 void SetSecondaryHoleLayers( const std::optional<PNS_LAYER_RANGE>& aLayers )
274 {
275 m_secondaryHoleLayers = aLayers;
276 }
277
278 std::optional<PNS_LAYER_RANGE> SecondaryHoleLayers() const
279 {
281 }
282
283 void SetSecondaryHolePostMachining( const std::optional<PAD_DRILL_POST_MACHINING_MODE>& aPostMachining )
284 {
285 m_secondaryPostMachining = aPostMachining;
286 }
287
288 std::optional<PAD_DRILL_POST_MACHINING_MODE> SecondaryHolePostMachining() const
289 {
291 }
292
293 bool IsFree() const { return m_isFree; }
294 void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
295
296 bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
297 int aCollisionMask = ITEM::ANY_T, int aMaxIterations = 10 );
298
299 bool PushoutForce( NODE* aNode, const ITEM* aOther, VECTOR2I& aForce );
300
301 const SHAPE* Shape( int aLayer ) const override
302 {
303 int layer = EffectiveLayer( aLayer );
304 wxCHECK( m_shapes.contains( layer ), nullptr );
305 return &m_shapes.at( layer );
306 }
307
308 VIA* Clone() const override;
309
310 const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
311 int aLayer = -1 ) const override;
312
313 virtual VECTOR2I Anchor( int n ) const override
314 {
315 return m_pos;
316 }
317
318 virtual int AnchorCount() const override
319 {
320 return 1;
321 }
322
323 OPT_BOX2I ChangedArea( const VIA* aOther ) const;
324
325 const VIA_HANDLE MakeHandle() const;
326
327 virtual void SetHole( HOLE* aHole ) override
328 {
329 if( m_hole && m_hole->BelongsTo( this ) )
330 delete m_hole;
331
332 m_hole = aHole;
333 m_hole->SetParentPadVia( this );
334 m_hole->SetOwner( this );
335 m_hole->SetLayers( m_holeLayers );
336 }
337
338 virtual bool HasHole() const override { return true; }
339 virtual HOLE *Hole() const override { return m_hole; }
340
341 virtual const std::string Format() const override;
342
343private:
345
347 std::map<int, int> m_diameters;
348 std::map<int, SHAPE_CIRCLE> m_shapes;
349
357
358 std::optional<PNS_LAYER_RANGE> m_secondaryHoleLayers;
359 std::optional<int> m_secondaryDrill;
360
361 std::optional<PAD_DRILL_POST_MACHINING_MODE> m_primaryPostMachining;
362 std::optional<PAD_DRILL_POST_MACHINING_MODE> m_secondaryPostMachining;
363};
364
365
366class VVIA : public VIA
367{
368public:
369 VVIA( const VECTOR2I& aPos, int aLayer, int aDiameter, NET_HANDLE aNet ) :
370 VIA( aPos, PNS_LAYER_RANGE( aLayer, aLayer ), aDiameter, aDiameter / 2, aNet )
371 {
372 m_isVirtual = true;
373 }
374
375 bool HasHole() const override { return false; }
376};
377
378}
379
380#endif
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:926
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:98
BOARD_ITEM * Parent() const
Definition pns_item.h:199
void SetLayers(const PNS_LAYER_RANGE &aLayers)
Definition pns_item.h:213
bool m_isVirtual
Definition pns_item.h:330
void SetSourceItem(BOARD_ITEM *aSourceItem)
Definition pns_item.h:201
const PNS_LAYER_RANGE & Layers() const
Definition pns_item.h:212
bool m_movable
Definition pns_item.h:325
virtual NET_HANDLE Net() const
Definition pns_item.h:210
bool m_routable
Definition pns_item.h:329
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:173
void SetNet(NET_HANDLE aNet)
Definition pns_item.h:209
BOARD_ITEM * GetSourceItem() const
Definition pns_item.h:202
void SetParent(BOARD_ITEM *aParent)
Definition pns_item.h:191
int m_marker
Definition pns_item.h:327
int m_rank
Definition pns_item.h:328
LINKED_ITEM(PnsKind aKind)
Keep the router "world" - i.e.
Definition pns_node.h:232
int Diameter(int aLayer) const
Definition pns_via.h:226
void SetDiameter(int aLayer, int aDiameter)
Definition pns_via.h:233
std::optional< PAD_DRILL_POST_MACHINING_MODE > m_secondaryPostMachining
Definition pns_via.h:362
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition pns_via.cpp:290
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:190
int m_drill
Definition pns_via.h:350
virtual VECTOR2I Anchor(int n) const override
Definition pns_via.h:313
VIA(const VIA &aB)
Definition pns_via.h:123
const VECTOR2I & Pos() const
Definition pns_via.h:205
void SetSecondaryHolePostMachining(const std::optional< PAD_DRILL_POST_MACHINING_MODE > &aPostMachining)
Definition pns_via.h:283
virtual void SetHole(HOLE *aHole) override
Definition pns_via.h:327
std::optional< PAD_DRILL_POST_MACHINING_MODE > SecondaryHolePostMachining() const
Definition pns_via.h:288
std::optional< int > m_secondaryDrill
Definition pns_via.h:359
std::map< int, int > m_diameters
May contain 1..n diameters depending on m_stackMode.
Definition pns_via.h:347
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition pns_via.h:222
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:99
const VIA_HANDLE MakeHandle() const
Definition pns_via.cpp:309
const SHAPE * Shape(int aLayer) const override
Return the geometrical shape of the item.
Definition pns_via.h:301
VIATYPE ViaType() const
Definition pns_via.h:218
virtual const std::string Format() const override
Definition pns_via.cpp:320
std::optional< PNS_LAYER_RANGE > SecondaryHoleLayers() const
Definition pns_via.h:278
bool PushoutForce(NODE *aNode, const VECTOR2I &aDirection, VECTOR2I &aForce, int aCollisionMask=ITEM::ANY_T, int aMaxIterations=10)
Definition pns_via.cpp:143
virtual int AnchorCount() const override
Definition pns_via.h:318
std::map< int, SHAPE_CIRCLE > m_shapes
Definition pns_via.h:348
virtual HOLE * Hole() const override
Definition pns_via.h:339
void SetIsFree(bool aIsFree)
Definition pns_via.h:294
void SetViaType(VIATYPE aViaType)
Definition pns_via.h:219
int EffectiveLayer(int aLayer) const
Definition pns_via.cpp:33
int Drill() const
Definition pns_via.h:246
void SetPos(const VECTOR2I &aPos)
Definition pns_via.h:207
std::optional< int > SecondaryDrill() const
Definition pns_via.h:271
VIA & operator=(const VIA &aB)
Definition pns_via.h:157
std::optional< PAD_DRILL_POST_MACHINING_MODE > HolePostMachining() const
Definition pns_via.h:264
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
Definition pns_via.h:221
void SetDrill(int aDrill)
Definition pns_via.h:248
VIATYPE m_viaType
Definition pns_via.h:352
UNCONNECTED_LAYER_MODE m_unconnectedLayerMode
Definition pns_via.h:353
void SetHoleLayers(const PNS_LAYER_RANGE &aLayers)
Definition pns_via.cpp:87
bool ConnectsLayer(int aLayer) const
Definition pns_via.cpp:78
virtual ~VIA()
Definition pns_via.h:151
HOLE * m_hole
Definition pns_via.h:355
bool PadstackMatches(const VIA &aOther) const
Definition pns_via.cpp:108
void SetSecondaryHoleLayers(const std::optional< PNS_LAYER_RANGE > &aLayers)
Definition pns_via.h:273
void SetSecondaryDrill(const std::optional< int > &aDrill)
Definition pns_via.h:266
bool IsFree() const
Definition pns_via.h:293
VECTOR2I m_pos
Definition pns_via.h:351
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition pns_via.cpp:235
const PNS_LAYER_RANGE & HoleLayers() const
Definition pns_via.h:257
static constexpr int ALL_LAYERS
Definition pns_via.h:77
static constexpr int INNER_LAYERS
Definition pns_via.h:78
std::optional< PAD_DRILL_POST_MACHINING_MODE > m_primaryPostMachining
Definition pns_via.h:361
void SetStackMode(STACK_MODE aStackMode)
Definition pns_via.cpp:96
void SetHolePostMachining(const std::optional< PAD_DRILL_POST_MACHINING_MODE > &aPostMachining)
Definition pns_via.h:259
PNS_LAYER_RANGE m_holeLayers
Definition pns_via.h:356
bool HasUniqueShapeLayers() const override
Definition pns_via.h:203
bool m_isFree
Definition pns_via.h:354
STACK_MODE StackMode() const
Definition pns_via.h:195
STACK_MODE m_stackMode
Definition pns_via.h:344
virtual bool HasHole() const override
Definition pns_via.h:338
std::optional< PNS_LAYER_RANGE > m_secondaryHoleLayers
Definition pns_via.h:358
VIA * Clone() const override
Return a deep copy of the item.
Definition pns_via.cpp:253
VVIA(const VECTOR2I &aPos, int aLayer, int aDiameter, NET_HANDLE aNet)
Definition pns_via.h:369
bool HasHole() const override
Definition pns_via.h:375
Represent a contiguous set of PCB layers.
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:55
UNCONNECTED_LAYER_MODE
Definition padstack.h:128
VIATYPE
Definition pcb_track.h:67
@ THROUGH
Definition pcb_track.h:68
VIA_HANDLE(VECTOR2I aPos, PNS_LAYER_RANGE aLayers, NET_HANDLE aNet)
Definition pns_via.h:47
VECTOR2I pos
Definition pns_via.h:54
NET_HANDLE net
Definition pns_via.h:56
PNS_LAYER_RANGE layers
Definition pns_via.h:55
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695