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  VIA_T = 16,
67  ANY_T = 0xff
68  };
69 
70  ITEM( PnsKind aKind )
71  {
72  m_net = UnusedNet;
73  m_movable = true;
74  m_kind = aKind;
75  m_parent = NULL;
76  m_owner = NULL;
77  m_marker = 0;
78  m_rank = -1;
79  m_routable = true;
80  }
81 
82  ITEM( const ITEM& aOther )
83  {
84  m_layers = aOther.m_layers;
85  m_net = aOther.m_net;
86  m_movable = aOther.m_movable;
87  m_kind = aOther.m_kind;
88  m_parent = aOther.m_parent;
89  m_owner = aOther.m_owner; // fixme: wtf this was null?
90  m_marker = aOther.m_marker;
91  m_rank = aOther.m_rank;
92  m_routable = aOther.m_routable;
93  }
94 
95  virtual ~ITEM();
96 
102  virtual ITEM* Clone() const = 0;
103 
104  /*
105  * Function Hull()
106  *
107  * Returns a convex polygon "hull" of a the item, that is used as the walk-around
108  * path.
109  * @param aClearance defines how far from the body of the item the hull should be,
110  * @param aWalkaroundThickness is the width of the line that walks around this hull.
111  */
112  virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0 ) const
113  {
114  return SHAPE_LINE_CHAIN();
115  }
116 
122  PnsKind Kind() const
123  {
124  return m_kind;
125  }
126 
132  bool OfKind( int aKindMask ) const
133  {
134  return ( aKindMask & m_kind ) != 0;
135  }
136 
142  std::string KindStr() const;
143 
144  void SetParent( BOARD_CONNECTED_ITEM* aParent ) { m_parent = aParent; }
145  BOARD_CONNECTED_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 
162  bool LayersOverlap( const ITEM* aOther ) const
163  {
164  return Layers().Overlaps( aOther->Layers() );
165  }
166 
172  NODE* Owner() const { return m_owner; }
173 
179  void SetOwner( NODE* aOwner ) { m_owner = aOwner; }
180 
186  bool BelongsTo( NODE* aNode ) const
187  {
188  return m_owner == aNode;
189  }
190 
204  virtual bool Collide( const ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I* aMTV,
205  const NODE* aParentNode, bool aDifferentNetsOnly = true ) const;
206 
213  virtual const SHAPE* Shape() const
214  {
215  return NULL;
216  }
217 
218  virtual void Mark( int aMarker ) { m_marker = aMarker; }
219  virtual void Unmark( int aMarker = -1 ) { m_marker &= ~aMarker; }
220  virtual int Marker() const { return m_marker; }
221 
222  virtual void SetRank( int aRank ) { m_rank = aRank; }
223  virtual int Rank() const { return m_rank; }
224 
225  virtual VECTOR2I Anchor( int n ) const
226  {
227  return VECTOR2I();
228  }
229 
230  virtual int AnchorCount() const
231  {
232  return 0;
233  }
234 
235  bool IsLocked() const
236  {
237  return Marker() & MK_LOCKED;
238  }
239 
240  void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
241  bool IsRoutable() const { return m_routable; }
242 
243 private:
244  bool collideSimple( const ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I* aMTV,
245  const NODE* aParentNode, bool aDifferentNetsOnly ) const;
246 
247 protected:
249 
253 
254  bool m_movable;
255  int m_net;
256  int m_marker;
257  int m_rank;
259 };
260 
261 template< typename T, typename S >
262 std::unique_ptr< T > ItemCast( std::unique_ptr< S > aPtr )
263 {
264  static_assert(std::is_base_of< ITEM, S >::value, "Need to be handed a ITEM!");
265  static_assert(std::is_base_of< ITEM, T >::value, "Need to cast to an ITEM!");
266  return std::unique_ptr< T >( static_cast<T*>(aPtr.release()) );
267 }
268 
269 template< typename T >
270 std::unique_ptr< typename std::remove_const< T >::type > Clone( const T& aItem )
271 {
272  static_assert(std::is_base_of< ITEM, T >::value, "Need to be handed an ITEM!");
273  return std::unique_ptr< typename std::remove_const< T >::type >( aItem.Clone() );
274 }
275 
276 }
277 
278 #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:262
void SetOwner(NODE *aOwner)
Functon SetOwner()
Definition: pns_item.h:179
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:145
virtual int Layer() const
Definition: pns_item.h:154
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:250
NODE.
Definition: pns_node.h:140
virtual ~ITEM()
Definition: pns_item.cpp:85
bool IsRoutable() const
Definition: pns_item.h:241
void SetLayer(int aLayer)
Definition: pns_item.h:153
virtual int AnchorCount() const
Definition: pns_item.h:230
virtual void Unmark(int aMarker=-1)
Definition: pns_item.h:219
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
NODE * m_owner
Definition: pns_item.h:251
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:252
int m_rank
Definition: pns_item.h:257
bool m_movable
Definition: pns_item.h:254
ITEM(PnsKind aKind)
Definition: pns_item.h:70
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
bool m_routable
Definition: pns_item.h:258
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:256
int Start() const
Definition: pns_layerset.h:83
void SetNet(int aNet)
Definition: pns_item.h:147
bool LayersOverlap(const ITEM *aOther) const
Function LayersOverlap()
Definition: pns_item.h:162
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:144
void SetRoutable(bool aRoutable)
Definition: pns_item.h:240
bool BelongsTo(NODE *aNode) const
Function BelongsTo()
Definition: pns_item.h:186
#define NULL
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:213
int Net() const
Definition: pns_item.h:148
SHAPE.
Definition: shape.h:60
virtual void SetRank(int aRank)
Definition: pns_item.h:222
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:151
int m_net
Definition: pns_item.h:255
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:270
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:225
PnsKind
Supported item types
Definition: pns_item.h:59
PnsKind m_kind
Definition: pns_item.h:248
virtual int Rank() const
Definition: pns_item.h:223
SHAPE_LINE_CHAIN.
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:132
bool IsLocked() const
Definition: pns_item.h:235
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122
virtual void Mark(int aMarker)
Definition: pns_item.h:218
ITEM(const ITEM &aOther)
Definition: pns_item.h:82
NODE * Owner() const
Function Owner()
Definition: pns_item.h:172
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0) const
Definition: pns_item.h:112
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:150
virtual int Marker() const
Definition: pns_item.h:220