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 = NULL;
79  m_owner = NULL;
80  m_marker = 0;
81  m_rank = -1;
82  m_routable = true;
83  }
84 
85  ITEM( const ITEM& aOther )
86  {
87  m_layers = aOther.m_layers;
88  m_net = aOther.m_net;
89  m_movable = aOther.m_movable;
90  m_kind = aOther.m_kind;
91  m_parent = aOther.m_parent;
92  m_owner = aOther.m_owner; // fixme: wtf this was null?
93  m_marker = aOther.m_marker;
94  m_rank = aOther.m_rank;
95  m_routable = aOther.m_routable;
96  }
97 
98  virtual ~ITEM();
99 
103  virtual ITEM* Clone() const = 0;
104 
105  /*
106  * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
107  *
108  * @param aClearance defines how far from the body of the item the hull should be,
109  * @param aWalkaroundThickness is the width of the line that walks around this hull.
110  */
111  virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
112  int aLayer = -1 ) const
113  {
114  return SHAPE_LINE_CHAIN();
115  }
116 
117  virtual const SHAPE_LINE_CHAIN HoleHull( int aClearance, int aWalkaroundThickness,
118  int aLayer ) const
119  {
120  return SHAPE_LINE_CHAIN();
121  }
122 
126  PnsKind Kind() const
127  {
128  return m_kind;
129  }
130 
134  bool OfKind( int aKindMask ) const
135  {
136  return ( aKindMask & m_kind ) != 0;
137  }
138 
142  std::string KindStr() const;
143 
144  void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
145  BOARD_ITEM* Parent() const { return m_parent; }
146 
147  void SetNet( int aNet ) { m_net = aNet; }
148  int Net() const { return m_net; }
149 
150  const LAYER_RANGE& Layers() const { return m_layers; }
151  void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
152 
153  void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
154  virtual int Layer() const { return Layers().Start(); }
155 
159  bool LayersOverlap( const ITEM* aOther ) const
160  {
161  return Layers().Overlaps( aOther->Layers() );
162  }
163 
167  NODE* Owner() const { return m_owner; }
168 
172  void SetOwner( NODE* aOwner ) { m_owner = aOwner; }
173 
177  bool BelongsTo( NODE* aNode ) const
178  {
179  return m_owner == aNode;
180  }
181 
191  bool Collide( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly = true ) const;
192 
196  virtual const SHAPE* Shape() const
197  {
198  return nullptr;
199  }
200 
201  virtual const SHAPE* Hole() const
202  {
203  return nullptr;
204  }
205 
206  virtual void Mark( int aMarker ) const { m_marker = aMarker; }
207  virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
208  virtual int Marker() const { return m_marker; }
209 
210  virtual void SetRank( int aRank ) { m_rank = aRank; }
211  virtual int Rank() const { return m_rank; }
212 
213  virtual VECTOR2I Anchor( int n ) const
214  {
215  return VECTOR2I();
216  }
217 
218  virtual int AnchorCount() const
219  {
220  return 0;
221  }
222 
223  bool IsLocked() const
224  {
225  return Marker() & MK_LOCKED;
226  }
227 
228  void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
229  bool IsRoutable() const { return m_routable; }
230 
231 private:
232  bool collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly ) const;
233 
234 protected:
236 
240 
241  bool m_movable;
242  int m_net;
243  mutable int m_marker;
244  int m_rank;
246 };
247 
248 template<typename T, typename S>
249 std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
250 {
251  static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
252  static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
253  return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
254 }
255 
256 template<typename T>
257 std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
258 {
259  static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
260  return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
261 }
262 
263 }
264 
265 #endif // __PNS_ITEM_H
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:111
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:201
void SetOwner(NODE *aOwner)
Set the node that owns this item.
Definition: pns_item.h:172
virtual int Layer() const
Definition: pns_item.h:154
Keep the router "world" - i.e.
Definition: pns_node.h:149
virtual void Mark(int aMarker) const
Definition: pns_item.h:206
virtual ~ITEM()
Definition: pns_item.cpp:142
bool IsRoutable() const
Definition: pns_item.h:229
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
void SetLayer(int aLayer)
Definition: pns_item.h:153
virtual int AnchorCount() const
Definition: pns_item.h:218
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:144
NODE * m_owner
Definition: pns_item.h:238
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
LAYER_RANGE m_layers
Definition: pns_item.h:239
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:249
int m_rank
Definition: pns_item.h:244
BOARD_ITEM * Parent() const
Definition: pns_item.h:145
bool m_movable
Definition: pns_item.h:241
ITEM(PnsKind aKind)
Definition: pns_item.h:73
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:207
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
bool m_routable
Definition: pns_item.h:245
static const int UnusedNet
Supported item types.
Definition: pns_item.h:58
int m_marker
Definition: pns_item.h:243
int Start() const
Definition: pns_layerset.h:82
void SetNet(int aNet)
Definition: pns_item.h:147
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:159
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:237
void SetRoutable(bool aRoutable)
Definition: pns_item.h:228
bool BelongsTo(NODE *aNode) const
Definition: pns_item.h:177
#define NULL
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:196
int Net() const
Definition: pns_item.h:148
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:210
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:151
int m_net
Definition: pns_item.h:242
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:213
PnsKind m_kind
Definition: pns_item.h:235
virtual int Rank() const
Definition: pns_item.h:211
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:257
SHAPE_LINE_CHAIN.
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:134
bool IsLocked() const
Definition: pns_item.h:223
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:126
ITEM(const ITEM &aOther)
Definition: pns_item.h:85
NODE * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:167
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:117
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150
virtual int Marker() const
Definition: pns_item.h:208
bool collideSimple(const ITEM *aOther, const NODE *aNode, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:31