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 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 = 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  const std::string KindStr() const;
143 
150  {
151  m_parent = aParent;
152  }
153 
160  {
161  return m_parent;
162  }
163 
169  void SetNet( int aNet )
170  {
171  m_net = aNet;
172  }
173 
179  int Net() const
180  {
181  return m_net;
182  }
183 
184  bool InAnyNet() const
185  {
186  return m_net != UnusedNet;
187  }
188 
194  void SetLayers( const LAYER_RANGE& aLayers )
195  {
196  m_layers = aLayers;
197  }
198 
204  void SetLayer( int aLayer )
205  {
206  m_layers = LAYER_RANGE( aLayer, aLayer );
207  }
208 
214  const LAYER_RANGE& Layers() const
215  {
216  return m_layers;
217  }
218 
224  virtual int Layer() const
225  {
226  return Layers().Start();
227  }
228 
235  bool LayersOverlap( const ITEM* aOther ) const
236  {
237  return Layers().Overlaps( aOther->Layers() );
238  }
239 
246  void SetOwner( NODE* aOwner )
247  {
248  m_owner = aOwner;
249  }
250 
256  bool BelongsTo( NODE* aNode ) const
257  {
258  return m_owner == aNode;
259  }
260 
266  NODE* Owner() const { return m_owner; }
267 
282  virtual bool Collide( const ITEM* aOther, int aClearance, bool aNeedMTV,
283  VECTOR2I& aMTV, bool aDifferentNetsOnly = true ) const;
284 
290  bool Collide( const ITEM* aOther, int aClearance, bool aDifferentNetsOnly = true ) const
291  {
292  VECTOR2I dummy;
293 
294  return Collide( aOther, aClearance, false, dummy, aDifferentNetsOnly );
295  }
296 
303  virtual const SHAPE* Shape() const
304  {
305  return NULL;
306  }
307 
308  virtual void Mark( int aMarker )
309  {
310  m_marker = aMarker;
311  }
312 
313  virtual void Unmark( int aMarker = -1 )
314  {
315  m_marker &= ~aMarker;
316  }
317 
318  virtual int Marker() const
319  {
320  return m_marker;
321  }
322 
323  virtual void SetRank( int aRank )
324  {
325  m_rank = aRank;
326  }
327 
328  virtual int Rank() const
329  {
330  return m_rank;
331  }
332 
333  virtual VECTOR2I Anchor( int n ) const
334  {
335  return VECTOR2I();
336  }
337 
338  virtual int AnchorCount() const
339  {
340  return 0;
341  }
342 
343  bool IsLocked() const
344  {
345  return Marker() & MK_LOCKED;
346  }
347 
348  void SetRoutable( bool aRoutable )
349  {
350  m_routable = aRoutable;
351  }
352 
353  bool IsRoutable() const
354  {
355  return m_routable;
356  }
357 
358 private:
359  bool collideSimple( const ITEM* aOther, int aClearance, bool aNeedMTV,
360  VECTOR2I& aMTV, bool aDifferentNetsOnly ) const;
361 
362 protected:
364 
368 
369  bool m_movable;
370  int m_net;
371  int m_marker;
372  int m_rank;
374 };
375 
376 template< typename T, typename S >
377 std::unique_ptr< T > ItemCast( std::unique_ptr< S > aPtr )
378 {
379  static_assert(std::is_base_of< ITEM, S >::value, "Need to be handed a ITEM!");
380  static_assert(std::is_base_of< ITEM, T >::value, "Need to cast to an ITEM!");
381  return std::unique_ptr< T >( static_cast<T*>(aPtr.release()) );
382 }
383 
384 template< typename T >
385 std::unique_ptr< typename std::remove_const< T >::type > Clone( const T& aItem )
386 {
387  static_assert(std::is_base_of< ITEM, T >::value, "Need to be handed an ITEM!");
388  return std::unique_ptr< typename std::remove_const< T >::type >( aItem.Clone() );
389 }
390 
391 }
392 
393 #endif // __PNS_ITEM_H
Class 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:377
void SetOwner(NODE *aOwner)
Functon SetOwner()
Definition: pns_item.h:246
BOARD_CONNECTED_ITEM * Parent() const
Function Parent()
Definition: pns_item.h:159
virtual int Layer() const
Function Layer()
Definition: pns_item.h:224
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:365
Class NODE.
Definition: pns_node.h:136
virtual ~ITEM()
Definition: pns_item.cpp:88
bool IsRoutable() const
Definition: pns_item.h:353
void SetLayer(int aLayer)
Function SetLayer()
Definition: pns_item.h:204
virtual int AnchorCount() const
Definition: pns_item.h:338
virtual void Unmark(int aMarker=-1)
Definition: pns_item.h:313
bool collideSimple(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I &aMTV, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:27
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
NODE * m_owner
Definition: pns_item.h:366
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
LAYER_RANGE m_layers
Definition: pns_item.h:367
int m_rank
Definition: pns_item.h:372
bool m_movable
Definition: pns_item.h:369
ITEM(PnsKind aKind)
Definition: pns_item.h:70
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
bool m_routable
Definition: pns_item.h:373
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
static const int UnusedNet
Definition: pns_item.h:56
int m_marker
Definition: pns_item.h:371
int Start() const
Definition: pns_layerset.h:83
void SetNet(int aNet)
Function SetNet()
Definition: pns_item.h:169
bool LayersOverlap(const ITEM *aOther) const
Function LayersOverlap()
Definition: pns_item.h:235
void SetParent(BOARD_CONNECTED_ITEM *aParent)
Function SetParent()
Definition: pns_item.h:149
void SetRoutable(bool aRoutable)
Definition: pns_item.h:348
bool BelongsTo(NODE *aNode) const
Function BelongsTo()
Definition: pns_item.h:256
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:303
int Net() const
Function Net()
Definition: pns_item.h:179
Class SHAPE.
Definition: shape.h:58
virtual void SetRank(int aRank)
Definition: pns_item.h:323
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:194
int m_net
Definition: pns_item.h:370
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:385
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:333
PnsKind
Supported item types
Definition: pns_item.h:59
const std::string KindStr() const
Function KindStr()
Definition: pns_item.cpp:63
PnsKind m_kind
Definition: pns_item.h:363
virtual int Rank() const
Definition: pns_item.h:328
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
Class SHAPE_LINE_CHAIN.
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:132
bool IsLocked() const
Definition: pns_item.h:343
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122
virtual void Mark(int aMarker)
Definition: pns_item.h:308
ITEM(const ITEM &aOther)
Definition: pns_item.h:82
virtual bool Collide(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I &aMTV, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.cpp:44
bool Collide(const ITEM *aOther, int aClearance, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.h:290
NODE * Owner() const
Function Owner()
Definition: pns_item.h:266
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.
bool InAnyNet() const
Definition: pns_item.h:184
LineMarker
Definition: pns_item.h:39
Class LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:214
virtual int Marker() const
Definition: pns_item.h:318