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 NET_HANDLE net = nullptr;
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 NET_HANDLE aNet = nullptr, 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 VIA& operator=( const VIA& aB )
107 {
108 SetNet( aB.Net() );
109 SetLayers( aB.Layers() );
110 m_pos = aB.m_pos;
113 m_drill = aB.m_drill;
115 m_marker = aB.m_marker;
116 m_rank = aB.m_rank;
117 m_viaType = aB.m_viaType;
118 m_isFree = aB.m_isFree;
120 return *this;
121 }
122
123 static inline bool ClassOf( const ITEM* aItem )
124 {
125 return aItem && VIA_T == aItem->Kind();
126 }
127
128 const VECTOR2I& Pos() const { return m_pos; }
129
130 void SetPos( const VECTOR2I& aPos )
131 {
132 m_pos = aPos;
133 m_shape.SetCenter( aPos );
134
135 if( m_hole )
136 m_hole->SetCenter( aPos );
137 }
138
139 VIATYPE ViaType() const { return m_viaType; }
140 void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
141
142 int Diameter() const { return m_diameter; }
143
144 void SetDiameter( int aDiameter )
145 {
146 m_diameter = aDiameter;
148 }
149
150 int Drill() const { return m_drill; }
151
152 void SetDrill( int aDrill )
153 {
154 m_drill = aDrill;
155
156 if( m_hole )
157 m_hole->SetRadius( m_drill / 2 );
158 }
159
160 bool IsFree() const { return m_isFree; }
161 void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
162
163 bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
164 int aCollisionMask = ITEM::ANY_T, int aMaxIterations = 10 );
165
166 bool PushoutForce( NODE* aNode, const ITEM* aOther, VECTOR2I& aForce );
167
168 const SHAPE* Shape() const override { return &m_shape; }
169
170 VIA* Clone() const override;
171
172 const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
173 int aLayer = -1 ) const override;
174
175 virtual VECTOR2I Anchor( int n ) const override
176 {
177 return m_pos;
178 }
179
180 virtual int AnchorCount() const override
181 {
182 return 1;
183 }
184
185 OPT_BOX2I ChangedArea( const VIA* aOther ) const;
186
187 const VIA_HANDLE MakeHandle() const;
188
189 virtual void SetHole( HOLE* aHole ) override
190 {
191 if( m_hole && m_hole->BelongsTo( this ) )
192 delete m_hole;
193
194 m_hole = aHole;
195 m_hole->SetParentPadVia( this );
196 m_hole->SetOwner( this );
197 m_hole->SetLayers( m_layers ); // fixme: backdrill vias can have hole layer set different
198 // than copper layer set
199 }
200
201 virtual bool HasHole() const override { return true; }
202 virtual HOLE *Hole() const override { return m_hole; }
203
204 virtual const std::string Format() const override;
205
206private:
214};
215
216
217class VVIA : public VIA
218{
219public:
220 VVIA( const VECTOR2I& aPos, int aLayer, int aDiameter, NET_HANDLE aNet ) :
221 VIA( aPos, LAYER_RANGE( aLayer, aLayer ), aDiameter, aDiameter / 2, aNet )
222 {
223 m_isVirtual = true;
224 }
225
226 bool HasHole() const override { return false; }
227};
228
229}
230
231#endif
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:880
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:97
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:197
bool m_isVirtual
Definition: pns_item.h:295
virtual NET_HANDLE Net() const
Definition: pns_item.h:194
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:167
void SetNet(NET_HANDLE aNet)
Definition: pns_item.h:193
LAYER_RANGE m_layers
Definition: pns_item.h:288
const LAYER_RANGE & Layers() const
Definition: pns_item.h:196
int m_marker
Definition: pns_item.h:292
int m_rank
Definition: pns_item.h:293
Keep the router "world" - i.e.
Definition: pns_node.h:207
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition: pns_item.h:76
bool BelongsTo(const ITEM_OWNER *aNode) const
Definition: pns_item.h:81
VIA()
Definition: pns_via.h:53
OPT_BOX2I ChangedArea(const VIA *aOther) const
Definition: pns_via.cpp:180
static bool ClassOf(const ITEM *aItem)
Definition: pns_via.h:123
int m_drill
Definition: pns_via.h:208
virtual VECTOR2I Anchor(int n) const override
Definition: pns_via.h:175
VIA(const VIA &aB)
Definition: pns_via.h:82
const VECTOR2I & Pos() const
Definition: pns_via.h:128
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition: pns_via.h:168
virtual void SetHole(HOLE *aHole) override
Definition: pns_via.h:189
int Diameter() const
Definition: pns_via.h:142
const VIA_HANDLE MakeHandle() const
Definition: pns_via.cpp:193
void SetDiameter(int aDiameter)
Definition: pns_via.h:144
VIATYPE ViaType() const
Definition: pns_via.h:139
virtual const std::string Format() const override
Definition: pns_via.cpp:204
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:180
virtual HOLE * Hole() const override
Definition: pns_via.h:202
void SetIsFree(bool aIsFree)
Definition: pns_via.h:161
void SetViaType(VIATYPE aViaType)
Definition: pns_via.h:140
int Drill() const
Definition: pns_via.h:150
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:130
VIA & operator=(const VIA &aB)
Definition: pns_via.h:106
void SetDrill(int aDrill)
Definition: pns_via.h:152
int m_diameter
Definition: pns_via.h:207
VIATYPE m_viaType
Definition: pns_via.h:211
virtual ~VIA()
Definition: pns_via.h:100
HOLE * m_hole
Definition: pns_via.h:213
bool IsFree() const
Definition: pns_via.h:160
VECTOR2I m_pos
Definition: pns_via.h:209
const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const override
Definition: pns_via.cpp:143
VIA(const VECTOR2I &aPos, const LAYER_RANGE &aLayers, int aDiameter, int aDrill, NET_HANDLE aNet=nullptr, VIATYPE aViaType=VIATYPE::THROUGH)
Definition: pns_via.h:65
bool m_isFree
Definition: pns_via.h:212
virtual bool HasHole() const override
Definition: pns_via.h:201
SHAPE_CIRCLE m_shape
Definition: pns_via.h:210
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:158
VVIA(const VECTOR2I &aPos, int aLayer, int aDiameter, NET_HANDLE aNet)
Definition: pns_via.h:220
bool HasHole() const override
Definition: pns_via.h:226
void SetRadius(int aRadius)
Definition: shape_circle.h:108
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:113
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:54
VIATYPE
Definition: pcb_track.h:65
VECTOR2I pos
Definition: pns_via.h:45
NET_HANDLE net
Definition: pns_via.h:47
LAYER_RANGE layers
Definition: pns_via.h:46