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
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
226
227 bool ConnectsLayer( int aLayer ) const;
228
229 int Diameter( int aLayer ) const
230 {
231 int layer = EffectiveLayer( aLayer );
232 wxCHECK( m_diameters.contains( layer ), m_diameters.begin()->second );
233 return m_diameters.at( layer );
234 }
235
236 void SetDiameter( int aLayer, int aDiameter )
237 {
238 int layer = EffectiveLayer( aLayer );
239 m_diameters[layer] = aDiameter;
240
241 if( !m_shapes.contains( layer ) )
242 m_shapes[layer] = SHAPE_CIRCLE( m_pos, aDiameter / 2 );
243 else
244 m_shapes[layer].SetRadius( aDiameter / 2 );
245 }
246
247 bool PadstackMatches( const VIA& aOther ) const;
248
249 int Drill() const { return m_drill; }
250
251 void SetDrill( int aDrill )
252 {
253 m_drill = aDrill;
254
255 if( m_hole )
256 m_hole->SetRadius( m_drill / 2 );
257 }
258
259 void SetHoleLayers( const PNS_LAYER_RANGE& aLayers );
260 const PNS_LAYER_RANGE& HoleLayers() const { return m_holeLayers; }
261
262 void SetHolePostMachining( const std::optional<PAD_DRILL_POST_MACHINING_MODE>& aPostMachining )
263 {
264 m_primaryPostMachining = aPostMachining;
265 }
266
267 std::optional<PAD_DRILL_POST_MACHINING_MODE> HolePostMachining() const { return m_primaryPostMachining; }
268
269 void SetSecondaryDrill( const std::optional<int>& aDrill )
270 {
271 m_secondaryDrill = aDrill;
272 }
273
274 std::optional<int> SecondaryDrill() const { return m_secondaryDrill; }
275
276 void SetSecondaryHoleLayers( const std::optional<PNS_LAYER_RANGE>& aLayers )
277 {
278 m_secondaryHoleLayers = aLayers;
279 }
280
281 std::optional<PNS_LAYER_RANGE> SecondaryHoleLayers() const
282 {
284 }
285
286 void SetSecondaryHolePostMachining( const std::optional<PAD_DRILL_POST_MACHINING_MODE>& aPostMachining )
287 {
288 m_secondaryPostMachining = aPostMachining;
289 }
290
291 std::optional<PAD_DRILL_POST_MACHINING_MODE> SecondaryHolePostMachining() const
292 {
294 }
295
296 bool IsFree() const { return m_isFree; }
297 void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
298
299 bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
300 int aCollisionMask = ITEM::ANY_T, int aMaxIterations = 10 );
301
302 bool PushoutForce( NODE* aNode, const ITEM* aOther, VECTOR2I& aForce );
303
304 const SHAPE* Shape( int aLayer ) const override
305 {
306 int layer = EffectiveLayer( aLayer );
307 wxCHECK( m_shapes.contains( layer ), nullptr );
308 return &m_shapes.at( layer );
309 }
310
311 VIA* Clone() const override;
312
313 const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
314 int aLayer = -1 ) const override;
315
316 virtual VECTOR2I Anchor( int n ) const override
317 {
318 return m_pos;
319 }
320
321 virtual int AnchorCount() const override
322 {
323 return 1;
324 }
325
326 OPT_BOX2I ChangedArea( const VIA* aOther ) const;
327
328 const VIA_HANDLE MakeHandle() const;
329
330 virtual void SetHole( HOLE* aHole ) override
331 {
332 if( m_hole && m_hole->BelongsTo( this ) )
333 delete m_hole;
334
335 m_hole = aHole;
336 m_hole->SetParentPadVia( this );
337 m_hole->SetOwner( this );
338 m_hole->SetLayers( m_holeLayers );
339 }
340
341 virtual bool HasHole() const override { return true; }
342 virtual HOLE *Hole() const override { return m_hole; }
343
344 virtual const std::string Format() const override;
345
346private:
348
350 std::map<int, int> m_diameters;
351 std::map<int, SHAPE_CIRCLE> m_shapes;
352
360 std::optional<PNS_LAYER_RANGE> m_secondaryHoleLayers;
361 std::optional<int> m_secondaryDrill;
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
UNCONNECTED_LAYER_MODE
! Whether or not to remove the copper shape for unconnected layers
Definition padstack.h:168
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:229
void SetDiameter(int aLayer, int aDiameter)
Definition pns_via.h:236
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: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:353
virtual VECTOR2I Anchor(int n) const override
Definition pns_via.h:316
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:286
virtual void SetHole(HOLE *aHole) override
Definition pns_via.h:330
std::optional< PAD_DRILL_POST_MACHINING_MODE > SecondaryHolePostMachining() const
Definition pns_via.h:291
std::optional< int > m_secondaryDrill
Definition pns_via.h:361
std::map< int, int > m_diameters
May contain 1..n diameters depending on m_stackMode.
Definition pns_via.h:350
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:304
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:281
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:321
std::map< int, SHAPE_CIRCLE > m_shapes
Definition pns_via.h:351
virtual HOLE * Hole() const override
Definition pns_via.h:342
void SetIsFree(bool aIsFree)
Definition pns_via.h:297
void SetViaType(VIATYPE aViaType)
Definition pns_via.h:219
int EffectiveLayer(int aLayer) const
Definition pns_via.cpp:33
PADSTACK::UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
Definition pns_via.h:221
int Drill() const
Definition pns_via.h:249
void SetPos(const VECTOR2I &aPos)
Definition pns_via.h:207
std::optional< int > SecondaryDrill() const
Definition pns_via.h:274
VIA & operator=(const VIA &aB)
Definition pns_via.h:157
std::optional< PAD_DRILL_POST_MACHINING_MODE > HolePostMachining() const
Definition pns_via.h:267
void SetDrill(int aDrill)
Definition pns_via.h:251
VIATYPE m_viaType
Definition pns_via.h:355
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:358
bool PadstackMatches(const VIA &aOther) const
Definition pns_via.cpp:108
void SetSecondaryHoleLayers(const std::optional< PNS_LAYER_RANGE > &aLayers)
Definition pns_via.h:276
void SetSecondaryDrill(const std::optional< int > &aDrill)
Definition pns_via.h:269
bool IsFree() const
Definition pns_via.h:296
VECTOR2I m_pos
Definition pns_via.h:354
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition pns_via.cpp:235
void SetUnconnectedLayerMode(PADSTACK::UNCONNECTED_LAYER_MODE aMode)
Definition pns_via.h:222
const PNS_LAYER_RANGE & HoleLayers() const
Definition pns_via.h:260
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: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:262
PNS_LAYER_RANGE m_holeLayers
Definition pns_via.h:359
PADSTACK::UNCONNECTED_LAYER_MODE m_unconnectedLayerMode
Definition pns_via.h:356
bool HasUniqueShapeLayers() const override
Definition pns_via.h:203
bool m_isFree
Definition pns_via.h:357
STACK_MODE StackMode() const
Definition pns_via.h:195
STACK_MODE m_stackMode
Definition pns_via.h:347
virtual bool HasHole() const override
Definition pns_via.h:341
std::optional< PNS_LAYER_RANGE > m_secondaryHoleLayers
Definition pns_via.h:360
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
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