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-2019 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_ITEM_H
23 #define __PNS_ITEM_H
24 
25 #include <memory>
26 #include <math/vector2d.h>
27 
28 #include <geometry/shape.h>
30 
31 #include "pns_layerset.h"
32 
34 
35 namespace PNS {
36 
37 class NODE;
38 
39 enum LineMarker {
40  MK_HEAD = ( 1 << 0 ),
41  MK_VIOLATION = ( 1 << 3 ),
42  MK_LOCKED = ( 1 << 4 ),
43  MK_DP_COUPLED = ( 1 << 5 )
44 };
45 
46 
53 class ITEM
54 {
55 public:
56  static const int UnusedNet = INT_MAX;
57 
59  enum PnsKind
60  {
61  SOLID_T = 1,
62  LINE_T = 2,
63  JOINT_T = 4,
64  SEGMENT_T = 8,
65  ARC_T = 16,
66  VIA_T = 32,
68  ANY_T = 0xff
69  };
70 
71  ITEM( PnsKind aKind )
72  {
73  m_net = UnusedNet;
74  m_movable = true;
75  m_kind = aKind;
76  m_parent = NULL;
77  m_owner = NULL;
78  m_marker = 0;
79  m_rank = -1;
80  m_routable = true;
81  }
82 
83  ITEM( const ITEM& aOther )
84  {
85  m_layers = aOther.m_layers;
86  m_net = aOther.m_net;
87  m_movable = aOther.m_movable;
88  m_kind = aOther.m_kind;
89  m_parent = aOther.m_parent;
90  m_owner = aOther.m_owner; // fixme: wtf this was null?
91  m_marker = aOther.m_marker;
92  m_rank = aOther.m_rank;
93  m_routable = aOther.m_routable;
94  }
95 
96  virtual ~ITEM();
97 
103  virtual ITEM* Clone() const = 0;
104 
105  /*
106  * Function Hull()
107  *
108  * Returns a convex polygon "hull" of a the item, that is used as the walk-around
109  * path.
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 ) const
114  {
115  return SHAPE_LINE_CHAIN();
116  }
117 
123  PnsKind Kind() const
124  {
125  return m_kind;
126  }
127 
133  bool OfKind( int aKindMask ) const
134  {
135  return ( aKindMask & m_kind ) != 0;
136  }
137 
143  std::string KindStr() const;
144 
145  void SetParent( BOARD_CONNECTED_ITEM* aParent ) { m_parent = aParent; }
146  BOARD_CONNECTED_ITEM* Parent() const { return m_parent; }
147 
148  void SetNet( int aNet ) { m_net = aNet; }
149  int Net() const { return m_net; }
150 
151  const LAYER_RANGE& Layers() const { return m_layers; }
152  void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
153 
154  void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
155  virtual int Layer() const { return Layers().Start(); }
156 
163  bool LayersOverlap( const ITEM* aOther ) const
164  {
165  return Layers().Overlaps( aOther->Layers() );
166  }
167 
173  NODE* Owner() const { return m_owner; }
174 
180  void SetOwner( NODE* aOwner ) { m_owner = aOwner; }
181 
187  bool BelongsTo( NODE* aNode ) const
188  {
189  return m_owner == aNode;
190  }
191 
205  virtual bool Collide( const ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I* aMTV,
206  const NODE* aParentNode, bool aDifferentNetsOnly = true ) const;
207 
214  virtual const SHAPE* Shape() const
215  {
216  return NULL;
217  }
218 
219  virtual void Mark( int aMarker ) { m_marker = aMarker; }
220  virtual void Unmark( int aMarker = -1 ) { m_marker &= ~aMarker; }
221  virtual int Marker() const { return m_marker; }
222 
223  virtual void SetRank( int aRank ) { m_rank = aRank; }
224  virtual int Rank() const { return m_rank; }
225 
226  virtual VECTOR2I Anchor( int n ) const
227  {
228  return VECTOR2I();
229  }
230 
231  virtual int AnchorCount() const
232  {
233  return 0;
234  }
235 
236  bool IsLocked() const
237  {
238  return Marker() & MK_LOCKED;
239  }
240 
241  void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
242  bool IsRoutable() const { return m_routable; }
243 
244 private:
245  bool collideSimple( const ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I* aMTV,
246  const NODE* aParentNode, bool aDifferentNetsOnly ) const;
247 
248 protected:
250 
254 
255  bool m_movable;
256  int m_net;
257  int m_marker;
258  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
ITEM.
Definition: pns_item.h:53
virtual ITEM * Clone() const =0
Function Clone()
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:263
void SetOwner(NODE *aOwner)
Functon SetOwner()
Definition: pns_item.h:180
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:146
virtual int Layer() const
Definition: pns_item.h:155
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:251
NODE.
Definition: pns_node.h:145
virtual ~ITEM()
Definition: pns_item.cpp:86
bool IsRoutable() const
Definition: pns_item.h:242
void SetLayer(int aLayer)
Definition: pns_item.h:154
virtual int AnchorCount() const
Definition: pns_item.h:231
virtual void Unmark(int aMarker=-1)
Definition: pns_item.h:220
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
NODE * m_owner
Definition: pns_item.h:252
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
virtual bool Collide(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I *aMTV, const NODE *aParentNode, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.cpp:48
LAYER_RANGE m_layers
Definition: pns_item.h:253
int m_rank
Definition: pns_item.h:258
bool m_movable
Definition: pns_item.h:255
ITEM(PnsKind aKind)
Definition: pns_item.h:71
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool m_routable
Definition: pns_item.h:259
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
static const int UnusedNet
Definition: pns_item.h:56
int m_marker
Definition: pns_item.h:257
int Start() const
Definition: pns_layerset.h:83
void SetNet(int aNet)
Definition: pns_item.h:148
bool LayersOverlap(const ITEM *aOther) const
Function LayersOverlap()
Definition: pns_item.h:163
bool collideSimple(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I *aMTV, const NODE *aParentNode, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:30
std::string KindStr() const
Function KindStr()
Definition: pns_item.cpp:71
void SetParent(BOARD_CONNECTED_ITEM *aParent)
Definition: pns_item.h:145
void SetRoutable(bool aRoutable)
Definition: pns_item.h:241
bool BelongsTo(NODE *aNode) const
Function BelongsTo()
Definition: pns_item.h:187
#define NULL
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:214
int Net() const
Definition: pns_item.h:149
SHAPE.
Definition: shape.h:60
virtual void SetRank(int aRank)
Definition: pns_item.h:223
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:152
int m_net
Definition: pns_item.h:256
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:271
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:226
PnsKind
Supported item types
Definition: pns_item.h:59
PnsKind m_kind
Definition: pns_item.h:249
virtual int Rank() const
Definition: pns_item.h:224
SHAPE_LINE_CHAIN.
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:133
bool IsLocked() const
Definition: pns_item.h:236
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
virtual void Mark(int aMarker)
Definition: pns_item.h:219
ITEM(const ITEM &aOther)
Definition: pns_item.h:83
NODE * Owner() const
Function Owner()
Definition: pns_item.h:173
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0) const
Definition: pns_item.h:113
Push and Shove diff pair dimensions (gap) settings dialog.
LineMarker
Definition: pns_item.h:39
LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151
virtual int Marker() const
Definition: pns_item.h:221