Horizon
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 
33 namespace PNS {
34 
35 class 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
40 struct VIA_HANDLE
41 {
42  bool valid = false;
43  VECTOR2I pos;
44  LAYER_RANGE layers;
45  int net;
46 };
47 
48 class VIA : public ITEM
49 {
50 public:
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  }
60 
61  VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aDiameter, int aDrill,
62  int aNet = -1, VIATYPE aViaType = VIATYPE::THROUGH ) :
63  ITEM( VIA_T )
64  {
65  SetNet( aNet );
66  SetLayers( aLayers );
67  m_pos = aPos;
68  m_diameter = aDiameter;
69  m_drill = aDrill;
70  m_shape = SHAPE_CIRCLE( aPos, aDiameter / 2 );
71  m_hole = SHAPE_CIRCLE( m_pos, aDrill / 2 );
72  m_viaType = aViaType;
73  m_isFree = false;
74  m_isVirtual = false;
75  }
76 
77  VIA( const VIA& aB ) :
78  ITEM( aB )
79  {
80  SetNet( aB.Net() );
81  SetLayers( aB.Layers() );
82  m_pos = aB.m_pos;
83  m_diameter = aB.m_diameter;
84  m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
85  m_hole = SHAPE_CIRCLE( m_pos, aB.m_drill / 2 );
86  m_marker = aB.m_marker;
87  m_rank = aB.m_rank;
88  m_drill = aB.m_drill;
89  m_viaType = aB.m_viaType;
90  m_isFree = aB.m_isFree;
91  m_isVirtual = aB.m_isVirtual;
92  }
93 
94  static inline bool ClassOf( const ITEM* aItem )
95  {
96  return aItem && VIA_T == aItem->Kind();
97  }
98 
99  const VECTOR2I& Pos() const { return m_pos; }
100 
101  void SetPos( const VECTOR2I& aPos )
102  {
103  m_pos = aPos;
104  m_shape.SetCenter( aPos );
105  m_hole.SetCenter( aPos );
106  }
107 
108  VIATYPE ViaType() const { return m_viaType; }
109  void SetViaType( VIATYPE aViaType ) { m_viaType = aViaType; }
110 
111  int Diameter() const { return m_diameter; }
112 
113  void SetDiameter( int aDiameter )
114  {
115  m_diameter = aDiameter;
116  m_shape.SetRadius( m_diameter / 2 );
117  }
118 
119  int Drill() const { return m_drill; }
120 
121  void SetDrill( int aDrill )
122  {
123  m_drill = aDrill;
124  m_hole.SetRadius( m_drill / 2 );
125  }
126 
127  bool IsFree() const { return m_isFree; }
128  void SetIsFree( bool aIsFree ) { m_isFree = aIsFree; }
129 
130  bool PushoutForce( NODE* aNode, const VECTOR2I& aDirection, VECTOR2I& aForce,
131  bool aSolidsOnly = true, int aMaxIterations = 10 );
132 
133  const SHAPE* Shape() const override { return &m_shape; }
134 
135  const SHAPE_CIRCLE* Hole() const override { return &m_hole; }
136  void SetHole( const SHAPE_CIRCLE& aHole ) { m_hole = aHole; }
137 
138  VIA* Clone() const override;
139 
140  const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
141  int aLayer = -1 ) const override;
142 
143  virtual VECTOR2I Anchor( int n ) const override
144  {
145  return m_pos;
146  }
147 
148  virtual int AnchorCount() const override
149  {
150  return 1;
151  }
152 
153  OPT_BOX2I ChangedArea( const VIA* aOther ) const;
154 
155  const VIA_HANDLE MakeHandle() const;
156 
157 private:
158  int m_diameter;
159  int m_drill;
160  VECTOR2I m_pos;
161  SHAPE_CIRCLE m_shape;
162  SHAPE_CIRCLE m_hole;
163  VIATYPE m_viaType;
164  bool m_isFree;
165 
166 };
167 
168 
169 class VVIA : public VIA
170 {
171 public:
172  VVIA( const VECTOR2I& aPos, int aLayer, int aDiameter, int aNet ) :
173  VIA( aPos, LAYER_RANGE( aLayer, aLayer ), aDiameter, aDiameter / 2, aNet )
174  {
175  m_isVirtual = true;
176  SetHole( SHAPE_CIRCLE( Pos(), 1 ) );
177  }
178 };
179 
180 }
181 
182 #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:133
VIA * Clone() const override
Return a deep copy of the item.
Definition: pns_via.cpp:89
Definition: pns_via.h:170
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