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