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