KiCad PCB EDA Suite
pns_item.h
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2017 CERN
5  * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  *
9  * This program is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef __PNS_ITEM_H
24 #define __PNS_ITEM_H
25 
26 #include <memory>
27 #include <math/vector2d.h>
28 
29 #include <geometry/shape.h>
31 
32 #include "pns_layerset.h"
33 
34 class BOARD_ITEM;
35 
36 namespace PNS {
37 
38 class NODE;
39 
40 enum LineMarker {
41  MK_HEAD = ( 1 << 0 ),
42  MK_VIOLATION = ( 1 << 3 ),
43  MK_LOCKED = ( 1 << 4 ),
44  MK_DP_COUPLED = ( 1 << 5 ),
45  MK_HOLE = ( 1 << 6 )
46 };
47 
48 
55 class ITEM
56 {
57 public:
58  static const int UnusedNet = INT_MAX;
59 
61  enum PnsKind
62  {
63  SOLID_T = 1,
64  LINE_T = 2,
65  JOINT_T = 4,
66  SEGMENT_T = 8,
67  ARC_T = 16,
68  VIA_T = 32,
70  ANY_T = 0xff
71  };
72 
73  ITEM( PnsKind aKind )
74  {
75  m_net = UnusedNet;
76  m_movable = true;
77  m_kind = aKind;
78  m_parent = nullptr;
79  m_owner = nullptr;
80  m_marker = 0;
81  m_rank = -1;
82  m_routable = true;
83  m_isVirtual = false;
84  }
85 
86  ITEM( const ITEM& aOther )
87  {
88  m_layers = aOther.m_layers;
89  m_net = aOther.m_net;
90  m_movable = aOther.m_movable;
91  m_kind = aOther.m_kind;
92  m_parent = aOther.m_parent;
93  m_owner = aOther.m_owner; // fixme: wtf this was null?
94  m_marker = aOther.m_marker;
95  m_rank = aOther.m_rank;
96  m_routable = aOther.m_routable;
97  m_isVirtual = aOther.m_isVirtual;
98  }
99 
100  virtual ~ITEM();
101 
105  virtual ITEM* Clone() const = 0;
106 
107  /*
108  * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
109  *
110  * @param aClearance defines how far from the body of the item the hull should be,
111  * @param aWalkaroundThickness is the width of the line that walks around this hull.
112  */
113  virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
114  int aLayer = -1 ) const
115  {
116  return SHAPE_LINE_CHAIN();
117  }
118 
119  virtual const SHAPE_LINE_CHAIN HoleHull( int aClearance, int aWalkaroundThickness,
120  int aLayer ) const
121  {
122  return SHAPE_LINE_CHAIN();
123  }
124 
128  PnsKind Kind() const
129  {
130  return m_kind;
131  }
132 
136  bool OfKind( int aKindMask ) const
137  {
138  return ( aKindMask & m_kind ) != 0;
139  }
140 
144  std::string KindStr() const;
145 
146  void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
147  BOARD_ITEM* Parent() const { return m_parent; }
148 
149  void SetNet( int aNet ) { m_net = aNet; }
150  int Net() const { return m_net; }
151 
152  const LAYER_RANGE& Layers() const { return m_layers; }
153  void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
154 
155  void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
156  virtual int Layer() const { return Layers().Start(); }
157 
161  bool LayersOverlap( const ITEM* aOther ) const
162  {
163  return Layers().Overlaps( aOther->Layers() );
164  }
165 
169  NODE* Owner() const { return m_owner; }
170 
174  void SetOwner( NODE* aOwner ) { m_owner = aOwner; }
175 
179  bool BelongsTo( NODE* aNode ) const
180  {
181  return m_owner == aNode;
182  }
183 
193  bool Collide( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly = true ) const;
194 
198  virtual const SHAPE* Shape() const
199  {
200  return nullptr;
201  }
202 
203  virtual const SHAPE* Hole() const
204  {
205  return nullptr;
206  }
207 
208  virtual void Mark( int aMarker ) const { m_marker = aMarker; }
209  virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
210  virtual int Marker() const { return m_marker; }
211 
212  virtual void SetRank( int aRank ) { m_rank = aRank; }
213  virtual int Rank() const { return m_rank; }
214 
215  virtual VECTOR2I Anchor( int n ) const
216  {
217  return VECTOR2I();
218  }
219 
220  virtual int AnchorCount() const
221  {
222  return 0;
223  }
224 
225  bool IsLocked() const
226  {
227  return Marker() & MK_LOCKED;
228  }
229 
230  void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
231  bool IsRoutable() const { return m_routable; }
232 
233  bool IsVirtual() const
234  {
235  return m_isVirtual;
236  }
237 
238 private:
239  bool collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly ) const;
240 
241 protected:
243 
247 
248  bool m_movable;
249  int m_net;
250  mutable int m_marker;
251  int m_rank;
254 };
255 
256 template<typename T, typename S>
257 std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
258 {
259  static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
260  static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
261  return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
262 }
263 
264 template<typename T>
265 std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
266 {
267  static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
268  return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
269 }
270 
271 }
272 
273 #endif // __PNS_ITEM_H
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:113
Base class for PNS router board items.
Definition: pns_item.h:55
virtual ITEM * Clone() const =0
Return a deep copy of the item.
virtual const SHAPE * Hole() const
Definition: pns_item.h:203
void SetOwner(NODE *aOwner)
Set the node that owns this item.
Definition: pns_item.h:174
virtual int Layer() const
Definition: pns_item.h:156
Keep the router "world" - i.e.
Definition: pns_node.h:144
virtual void Mark(int aMarker) const
Definition: pns_item.h:208
virtual ~ITEM()
Definition: pns_item.cpp:142
bool IsRoutable() const
Definition: pns_item.h:231
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void SetLayer(int aLayer)
Definition: pns_item.h:155
virtual int AnchorCount() const
Definition: pns_item.h:220
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:146
NODE * m_owner
Definition: pns_item.h:245
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
LAYER_RANGE m_layers
Definition: pns_item.h:246
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:257
int m_rank
Definition: pns_item.h:251
BOARD_ITEM * Parent() const
Definition: pns_item.h:147
bool m_movable
Definition: pns_item.h:248
ITEM(PnsKind aKind)
Definition: pns_item.h:73
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:209
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
bool m_routable
Definition: pns_item.h:252
static const int UnusedNet
Supported item types.
Definition: pns_item.h:58
bool IsVirtual() const
Definition: pns_item.h:233
int m_marker
Definition: pns_item.h:250
int Start() const
Definition: pns_layerset.h:82
void SetNet(int aNet)
Definition: pns_item.h:149
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:161
std::string KindStr() const
Returns the kind of the item, as string.
Definition: pns_item.cpp:126
BOARD_ITEM * m_parent
Definition: pns_item.h:244
void SetRoutable(bool aRoutable)
Definition: pns_item.h:230
bool BelongsTo(NODE *aNode) const
Definition: pns_item.h:179
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:198
int Net() const
Definition: pns_item.h:150
bool Collide(const ITEM *aOther, const NODE *aNode, bool aDifferentNetsOnly=true) const
Check for a collision (clearance violation) with between us and item aOther.
Definition: pns_item.cpp:97
An abstract shape on 2D plane.
Definition: shape.h:116
virtual void SetRank(int aRank)
Definition: pns_item.h:212
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:153
int m_net
Definition: pns_item.h:249
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:215
PnsKind m_kind
Definition: pns_item.h:242
virtual int Rank() const
Definition: pns_item.h:213
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:265
Represent a polyline (an zero-thickness chain of connected line segments).
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:136
bool m_isVirtual
Definition: pns_item.h:253
bool IsLocked() const
Definition: pns_item.h:225
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:128
ITEM(const ITEM &aOther)
Definition: pns_item.h:86
NODE * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:169
Push and Shove diff pair dimensions (gap) settings dialog.
LineMarker
Definition: pns_item.h:40
virtual const SHAPE_LINE_CHAIN HoleHull(int aClearance, int aWalkaroundThickness, int aLayer) const
Definition: pns_item.h:119
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
const LAYER_RANGE & Layers() const
Definition: pns_item.h:152
virtual int Marker() const
Definition: pns_item.h:210
bool collideSimple(const ITEM *aOther, const NODE *aNode, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:31