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 <[email protected]>
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;
85  }
86 
87  ITEM( const ITEM& aOther )
88  {
89  m_layers = aOther.m_layers;
90  m_net = aOther.m_net;
91  m_movable = aOther.m_movable;
92  m_kind = aOther.m_kind;
93  m_parent = aOther.m_parent;
94  m_owner = aOther.m_owner; // fixme: wtf this was null?
95  m_marker = aOther.m_marker;
96  m_rank = aOther.m_rank;
97  m_routable = aOther.m_routable;
98  m_isVirtual = aOther.m_isVirtual;
100  }
101 
102  virtual ~ITEM();
103 
107  virtual ITEM* Clone() const = 0;
108 
109  /*
110  * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
111  *
112  * @param aClearance defines how far from the body of the item the hull should be,
113  * @param aWalkaroundThickness is the width of the line that walks around this hull.
114  */
115  virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
116  int aLayer = -1 ) const
117  {
118  return SHAPE_LINE_CHAIN();
119  }
120 
121  virtual const SHAPE_LINE_CHAIN HoleHull( int aClearance, int aWalkaroundThickness,
122  int aLayer ) const
123  {
124  return SHAPE_LINE_CHAIN();
125  }
126 
130  PnsKind Kind() const
131  {
132  return m_kind;
133  }
134 
138  bool OfKind( int aKindMask ) const
139  {
140  return ( aKindMask & m_kind ) != 0;
141  }
142 
146  std::string KindStr() const;
147 
148  void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
149  BOARD_ITEM* Parent() const { return m_parent; }
150 
151  void SetNet( int aNet ) { m_net = aNet; }
152  int Net() const { return m_net; }
153 
154  const LAYER_RANGE& Layers() const { return m_layers; }
155  void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
156 
157  void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
158  virtual int Layer() const { return Layers().Start(); }
159 
163  bool LayersOverlap( const ITEM* aOther ) const
164  {
165  return Layers().Overlaps( aOther->Layers() );
166  }
167 
171  NODE* Owner() const { return m_owner; }
172 
176  void SetOwner( NODE* aOwner ) { m_owner = aOwner; }
177 
181  bool BelongsTo( NODE* aNode ) const
182  {
183  return m_owner == aNode;
184  }
185 
195  bool Collide( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly = true ) const;
196 
200  virtual const SHAPE* Shape() const
201  {
202  return nullptr;
203  }
204 
205  virtual const SHAPE* Hole() const
206  {
207  return nullptr;
208  }
209 
210  virtual void Mark( int aMarker ) const { m_marker = aMarker; }
211  virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
212  virtual int Marker() const { return m_marker; }
213 
214  virtual void SetRank( int aRank ) { m_rank = aRank; }
215  virtual int Rank() const { return m_rank; }
216 
217  virtual VECTOR2I Anchor( int n ) const
218  {
219  return VECTOR2I();
220  }
221 
222  virtual int AnchorCount() const
223  {
224  return 0;
225  }
226 
227  bool IsLocked() const
228  {
229  return Marker() & MK_LOCKED;
230  }
231 
232  void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
233  bool IsRoutable() const { return m_routable; }
234 
235  bool IsVirtual() const
236  {
237  return m_isVirtual;
238  }
239 
242 
243 private:
244  bool collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly ) const;
245 
246 protected:
248 
252 
253  bool m_movable;
254  int m_net;
255  mutable int m_marker;
256  int m_rank;
260 };
261 
262 template<typename T, typename S>
263 std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
264 {
265  static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
266  static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
267  return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
268 }
269 
270 template<typename T>
271 std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
272 {
273  static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
274  return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
275 }
276 
277 }
278 
279 #endif // __PNS_ITEM_H
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:115
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:205
void SetOwner(NODE *aOwner)
Set the node that owns this item.
Definition: pns_item.h:176
virtual int Layer() const
Definition: pns_item.h:158
Keep the router "world" - i.e.
Definition: pns_node.h:146
virtual void Mark(int aMarker) const
Definition: pns_item.h:210
virtual ~ITEM()
Definition: pns_item.cpp:176
bool IsRoutable() const
Definition: pns_item.h:233
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void SetLayer(int aLayer)
Definition: pns_item.h:157
virtual int AnchorCount() const
Definition: pns_item.h:222
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:148
NODE * m_owner
Definition: pns_item.h:250
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
LAYER_RANGE m_layers
Definition: pns_item.h:251
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:263
int m_rank
Definition: pns_item.h:256
BOARD_ITEM * Parent() const
Definition: pns_item.h:149
bool m_movable
Definition: pns_item.h:253
ITEM(PnsKind aKind)
Definition: pns_item.h:73
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:211
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
bool m_routable
Definition: pns_item.h:257
static const int UnusedNet
Supported item types.
Definition: pns_item.h:58
bool m_isCompoundShapePrimitive
Definition: pns_item.h:259
bool IsVirtual() const
Definition: pns_item.h:235
int m_marker
Definition: pns_item.h:255
int Start() const
Definition: pns_layerset.h:82
void SetNet(int aNet)
Definition: pns_item.h:151
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:163
std::string KindStr() const
Returns the kind of the item, as string.
Definition: pns_item.cpp:160
BOARD_ITEM * m_parent
Definition: pns_item.h:249
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:240
void SetRoutable(bool aRoutable)
Definition: pns_item.h:232
bool BelongsTo(NODE *aNode) const
Definition: pns_item.h:181
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:200
int Net() const
Definition: pns_item.h:152
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:131
An abstract shape on 2D plane.
Definition: shape.h:116
virtual void SetRank(int aRank)
Definition: pns_item.h:214
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:155
int m_net
Definition: pns_item.h:254
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:241
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:217
PnsKind m_kind
Definition: pns_item.h:247
virtual int Rank() const
Definition: pns_item.h:215
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:138
bool m_isVirtual
Definition: pns_item.h:258
bool IsLocked() const
Definition: pns_item.h:227
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:130
ITEM(const ITEM &aOther)
Definition: pns_item.h:87
NODE * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:171
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:121
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
const LAYER_RANGE & Layers() const
Definition: pns_item.h:154
virtual int Marker() const
Definition: pns_item.h:212
bool collideSimple(const ITEM *aOther, const NODE *aNode, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:32