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-2022 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
27#include <math/box2.h>
28
29#include "pcb_track.h"
30
31#include "pns_item.h"
32#include "pns_linked_item.h"
33
34namespace PNS {
35
36class NODE;
37
38// uniquely identifies a VIA within a NODE without using pointers. Used to
39// simplify (or complexifiy, depending on the point of view) the pointer management
40// in PNS::NODE. Sooner or later I'll have to fix it for good using smart pointers - twl
42{
43 bool valid = false;
46 int net = -1;
47};
48
49class VIA : public LINKED_ITEM
50{
51public:
52 VIA() :
54 {
55 m_diameter = 2; // Dummy value
56 m_drill = 0;
58 m_isFree = false;
59 m_isVirtual = false;
60 }
61
62 VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill,
63 int aNet = -1, VIATYPE aViaType = VIATYPE::THROUGH ) :
65 {
66 SetNet( aNet );
67 SetLayers( aLayers );
68 m_pos = aPos;
69 m_diameter = aDiameter;
70 m_drill = aDrill;
71 m_shape = SHAPE_CIRCLE( aPos, aDiameter / 2 );
72 m_hole = SHAPE_CIRCLE( m_pos, aDrill / 2 );
73 m_viaType = aViaType;
74 m_isFree = false;
75 m_isVirtual = false;
76 }
77
78 VIA( const VIA& aB ) :
79 LINKED_ITEM( aB )
80 {
81 SetNet( aB.Net() );
82 SetLayers( aB.Layers() );
83 m_pos = aB.m_pos;
86 m_hole = SHAPE_CIRCLE( m_pos, aB.m_drill / 2 );
87 m_marker = aB.m_marker;
88 m_rank = aB.m_rank;
89 m_drill = aB.m_drill;
91 m_isFree = aB.m_isFree;
93 }
94
95 static inline bool ClassOf( const ITEM* aItem )
96 {
97 return aItem && VIA_T == aItem->Kind();
98 }
99
100 const VECTOR2I& Pos() const { return m_pos; }
101
102 void SetPos( const VECTOR2I& aPos )
103 {
104 m_pos = aPos;
105 m_shape.SetCenter( aPos );
106 m_hole.SetCenter( aPos );
107 }
108
109 VIATYPE ViaType() const { return m_viaType; }
110 void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
111
112 int Diameter() const { return m_diameter; }
113
114 void SetDiameter( int aDiameter )
115 {
116 m_diameter = aDiameter;
118 }
119
120 int Drill() const { return m_drill; }
121
122 void SetDrill( int aDrill )
123 {
124 m_drill = aDrill;
125 m_hole.SetRadius( m_drill / 2 );
126 }
127
128 bool IsFree() const { return m_isFree; }
129 void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
130
131 bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
132 bool aSolidsOnly = true, int aMaxIterations = 10 );
133
134 bool PushoutForce( NODE* aNode, const ITEM* aOther, VECTOR2I& aForce );
135
136 const SHAPE* Shape() const override { return &m_shape; }
137
138 const SHAPE_CIRCLE* Hole() const override { return &m_hole; }
139 void SetHole( const SHAPE_CIRCLE& aHole ) { m_hole = aHole; }
140
141 VIA* Clone() const override;
142
143 const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
144 int aLayer = -1 ) const override;
145
146 const SHAPE_LINE_CHAIN HoleHull( int aClearance = 0, int aWalkaroundThickness = 0,
147 int aLayer = -1 ) const override;
148
149 virtual VECTOR2I Anchor( int n ) const override
150 {
151 return m_pos;
152 }
153
154 virtual int AnchorCount() const override
155 {
156 return 1;
157 }
158
159 OPT_BOX2I ChangedArea( const VIA* aOther ) const;
160
161 const VIA_HANDLE MakeHandle() const;
162
163private:
171
172};
173
174
175class VVIA : public VIA
176{
177public:
178 VVIA( const VECTOR2I& aPos, int aLayer, int aDiameter, int aNet ) :
179 VIA( aPos, LAYER_RANGE( aLayer, aLayer ), aDiameter, aDiameter / 2, aNet )
180 {
181 m_isVirtual = true;
182 SetHole( SHAPE_CIRCLE( Pos(), 1 ) );
183 }
184};
185
186}
187
188#endif
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:850
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
Base class for PNS router board items.
Definition: pns_item.h:56
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:157
bool m_isVirtual
Definition: pns_item.h:263
void SetNet(int aNet)
Definition: pns_item.h:153
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:132
const LAYER_RANGE & Layers() const
Definition: pns_item.h:156
int m_marker
Definition: pns_item.h:260
int Net() const
Definition: pns_item.h:154
int m_rank
Definition: pns_item.h:261
Keep the router "world" - i.e.
Definition: pns_node.h:155
VIA()
Definition: pns_via.h:52
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:157
static bool ClassOf(const ITEM *aItem)
Definition: pns_via.h:95
int m_drill
Definition: pns_via.h:165
virtual VECTOR2I Anchor(int n) const override
Definition: pns_via.h:149
VIA(const VIA &aB)
Definition: pns_via.h:78
void SetHole(const SHAPE_CIRCLE &aHole)
Definition: pns_via.h:139
const VECTOR2I & Pos() const
Definition: pns_via.h:100
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_via.h:136
const SHAPE_LINE_CHAIN HoleHull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:124
int Diameter() const
Definition: pns_via.h:112
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:169
void SetDiameter(int aDiameter)
Definition: pns_via.h:114
VIATYPE ViaType() const
Definition: pns_via.h:109
virtual int AnchorCount() const override
Definition: pns_via.h:154
void SetIsFree(bool aIsFree)
Definition: pns_via.h:129
void SetViaType(VIATYPE aViaType)
Definition: pns_via.h:110
int Drill() const
Definition: pns_via.h:120
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:102
void SetDrill(int aDrill)
Definition: pns_via.h:122
int m_diameter
Definition: pns_via.h:164
VIATYPE m_viaType
Definition: pns_via.h:169
bool IsFree() const
Definition: pns_via.h:128
bool PushoutForce(NODE *aNode, const VECTOR2I &aDirection, VECTOR2I &aForce, bool aSolidsOnly=true, int aMaxIterations=10)
Definition: pns_via.cpp:65
VECTOR2I m_pos
Definition: pns_via.h:166
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:109
VIA(const VECTOR2I &aPos, const LAYER_RANGE &aLayers, int aDiameter, int aDrill, int aNet=-1, VIATYPE aViaType=VIATYPE::THROUGH)
Definition: pns_via.h:62
bool m_isFree
Definition: pns_via.h:170
SHAPE_CIRCLE m_hole
Definition: pns_via.h:168
const SHAPE_CIRCLE * Hole() const override
Definition: pns_via.h:138
SHAPE_CIRCLE m_shape
Definition: pns_via.h:167
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:135
VVIA(const VECTOR2I &aPos, int aLayer, int aDiameter, int aNet)
Definition: pns_via.h:178
void SetRadius(int aRadius)
Definition: shape_circle.h:98
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:103
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:123
Push and Shove diff pair dimensions (gap) settings dialog.
VIATYPE
Definition: pcb_track.h:62
VECTOR2I pos
Definition: pns_via.h:44
LAYER_RANGE layers
Definition: pns_via.h:45