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 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 "layers_id_colors_and_visibility.h"
28 
29 #include "../class_track.h"
30 
31 #include "pns_item.h"
32 
33 namespace PNS {
34 
35 class NODE;
36 
37 class VIA : public ITEM
38 {
39 public:
40  VIA() :
41  ITEM( VIA_T )
42  {
43  m_diameter = 2; // Dummy value
44  m_drill = 0;
45  m_viaType = VIA_THROUGH;
46  }
47 
48  VIA( const VECTOR2I& aPos, const LAYER_RANGE& aLayers,
49  int aDiameter, int aDrill, int aNet = -1, VIATYPE_T aViaType = VIA_THROUGH ) :
50  ITEM( VIA_T )
51  {
52  SetNet( aNet );
53  SetLayers( aLayers );
54  m_pos = aPos;
55  m_diameter = aDiameter;
56  m_drill = aDrill;
57  m_shape = SHAPE_CIRCLE( aPos, aDiameter / 2 );
58  m_viaType = aViaType;
59 
60  //If we're a through-board via, use all layers regardless of the set passed
61  if( aViaType == VIA_THROUGH )
62  {
63  LAYER_RANGE allLayers( 0, MAX_CU_LAYERS - 1 );
64  SetLayers( allLayers );
65  }
66  }
67 
68 
69  VIA( const VIA& aB ) :
70  ITEM( VIA_T )
71  {
72  SetNet( aB.Net() );
73  SetLayers( aB.Layers() );
74  m_pos = aB.m_pos;
75  m_diameter = aB.m_diameter;
76  m_shape = SHAPE_CIRCLE( m_pos, m_diameter / 2 );
77  m_marker = aB.m_marker;
78  m_rank = aB.m_rank;
79  m_drill = aB.m_drill;
80  m_viaType = aB.m_viaType;
81  }
82 
83  static inline bool ClassOf( const ITEM* aItem )
84  {
85  return aItem && VIA_T == aItem->Kind();
86  }
87 
88 
89  const VECTOR2I& Pos() const
90  {
91  return m_pos;
92  }
93 
94  void SetPos( const VECTOR2I& aPos )
95  {
96  m_pos = aPos;
97  m_shape.SetCenter( aPos );
98  }
99 
100  VIATYPE_T ViaType() const
101  {
102  return m_viaType;
103  }
104 
105  void SetViaType( VIATYPE_T aViaType )
106  {
107  m_viaType = aViaType;
108  }
109 
110  int Diameter() const
111  {
112  return m_diameter;
113  }
114 
115  void SetDiameter( int aDiameter )
116  {
117  m_diameter = aDiameter;
118  m_shape.SetRadius( m_diameter / 2 );
119  }
120 
121  int Drill() const
122  {
123  return m_drill;
124  }
125 
126  void SetDrill( int aDrill )
127  {
128  m_drill = aDrill;
129  }
130 
131  bool PushoutForce( NODE* aNode,
132  const VECTOR2I& aDirection,
133  VECTOR2I& aForce,
134  bool aSolidsOnly = true,
135  int aMaxIterations = 10 );
136 
137  const SHAPE* Shape() const override
138  {
139  return &m_shape;
140  }
141 
142  VIA* Clone() const override;
143 
144  const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0 ) 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  OPT_BOX2I ChangedArea( const VIA* aOther ) const;
157 
158 private:
159  int m_diameter;
160  int m_drill;
161  VECTOR2I m_pos;
162  SHAPE_CIRCLE m_shape;
163  VIATYPE_T m_viaType;
164 };
165 
166 }
167 
168 #endif
PNS::ITEM::Layers
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:215
LAYER_RANGE
Class LAYER_RANGE.
Definition: pns_layerset.h:33
SHAPE_CIRCLE
Definition: shape_circle.h:31
PNS::VIA::Shape
const SHAPE * Shape() const override
Function Shape()
Definition: pns_via.h:137
PNS::ITEM::SetNet
void SetNet(int aNet)
Function SetNet()
Definition: pns_item.h:170
PNS::ITEM::Net
int Net() const
Function Net()
Definition: pns_item.h:180
VECTOR2< int >
PNS::VIA
Definition: pns_via.h:38
PNS::VIA::Clone
VIA * Clone() const override
Function Clone()
Definition: pns_via.cpp:84
PNS::ITEM::SetLayers
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:195
PNS::ITEM
Class ITEM.
Definition: pns_item.h:55
PNS::NODE
Class NODE.
Definition: pns_node.h:138
SHAPE_LINE_CHAIN
Class SHAPE_LINE_CHAIN.
Definition: shape_line_chain.h:50
PNS::ITEM::Kind
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
SHAPE
Class SHAPE.
Definition: shape.h:59