Horizon
Loading...
Searching...
No Matches
pns_via.h
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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
25#include <geometry/shape_line_chain.h>
26#include <geometry/shape_circle.h>
27#include <math/box2.h>
28
29#include "viatype.h"
30
31#include "pns_item.h"
32
33namespace PNS {
34
35class NODE;
36
37// uniquely identifies a VIA within a NODE without using pointers. Used to
38// simplify (or complexifiy, depending on the point of view) the pointer management
39// in PNS::NODE. Sooner or later I'll have to fix it for good using smart pointers - twl
41{
42 bool valid = false;
43 VECTOR2I pos;
44 LAYER_RANGE layers;
45 int net;
46};
47
48class VIA : public ITEM
49{
50public:
51 VIA() :
52 ITEM( VIA_T )
53 {
54 m_diameter = 2; // Dummy value
55 m_drill = 0;
56 m_viaType = VIATYPE::THROUGH;
57 m_isFree = false;
58 m_isVirtual = false;
59 m_definition = -1;
60 }
61
62 VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill,
63 int aNet = -1, VIATYPE aViaType = VIATYPE::THROUGH ) :
64 ITEM( VIA_T )
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 m_definition = -1;
77 }
78
79 VIA( const VIA& aB ) :
80 ITEM( aB )
81 {
82 SetNet( aB.Net() );
83 SetLayers( aB.Layers() );
84 m_pos = aB.m_pos;
85 m_diameter = aB.m_diameter;
86 m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
87 m_hole = SHAPE_CIRCLE( m_pos, aB.m_drill / 2 );
88 m_marker = aB.m_marker;
89 m_rank = aB.m_rank;
90 m_drill = aB.m_drill;
91 m_viaType = aB.m_viaType;
92 m_isFree = aB.m_isFree;
93 m_isVirtual = aB.m_isVirtual;
94 m_definition = aB.m_definition;
95 }
96
97 static inline bool ClassOf( const ITEM* aItem )
98 {
99 return aItem && VIA_T == aItem->Kind();
100 }
101
102 const VECTOR2I& Pos() const { return m_pos; }
103
104 void SetPos( const VECTOR2I& aPos )
105 {
106 m_pos = aPos;
107 m_shape.SetCenter( aPos );
108 m_hole.SetCenter( aPos );
109 }
110
111 VIATYPE ViaType() const { return m_viaType; }
112 void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
113
114 int Diameter() const { return m_diameter; }
115
116 void SetDiameter( int aDiameter )
117 {
118 m_diameter = aDiameter;
119 m_shape.SetRadius( m_diameter / 2 );
120 }
121
122 int Drill() const { return m_drill; }
123
124 void SetDrill( int aDrill )
125 {
126 m_drill = aDrill;
127 m_hole.SetRadius( m_drill / 2 );
128 }
129
130 bool IsFree() const { return m_isFree; }
131 void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
132
133 bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
134 bool aSolidsOnly = true, int aMaxIterations = 10 );
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 virtual VECTOR2I Anchor( int n ) const override
147 {
148 return m_pos;
149 }
150
151 virtual int AnchorCount() const override
152 {
153 return 1;
154 }
155
156 int Definition() const { return m_definition; }
157 void SetDefinition( int aDef ) { m_definition = aDef; }
158
159 OPT_BOX2I ChangedArea( const VIA* aOther ) const;
160
161 const VIA_HANDLE MakeHandle() const;
162
163private:
164 int m_diameter;
165 int m_drill;
166 VECTOR2I m_pos;
167 SHAPE_CIRCLE m_shape;
168 SHAPE_CIRCLE m_hole;
169 VIATYPE m_viaType;
170 bool m_isFree;
171 int m_definition;
172
173};
174
175
176class VVIA : public VIA
177{
178public:
179 VVIA( const VECTOR2I& aPos, int aLayer, int aDiameter, int aNet ) :
180 VIA( aPos, LAYER_RANGE( aLayer, aLayer ), aDiameter, aDiameter / 2, aNet )
181 {
182 m_isVirtual = true;
183 SetHole( SHAPE_CIRCLE( Pos(), 1 ) );
184 }
185};
186
187}
188
189#endif
Represent a contiguous set of PCB layers.
Definition pns_layerset.h:32
Base class for PNS router board items.
Definition pns_item.h:57
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:131
Keep the router "world" - i.e.
Definition pns_node.h:148
Definition pns_via.h:49
const SHAPE * Shape() const override
Return the geometrical shape of the item.
Definition pns_via.h:136
VIA * Clone() const override
Return a deep copy of the item.
Definition pns_via.cpp:89
Definition pns_via.h:177
Definition shape_circle.h:37
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition shape_line_chain.h:81
An abstract shape on 2D plane.
Definition shape.h:117
Definition pns_via.h:41