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  }
80 
81  ITEM( const ITEM& aOther )
82  {
83  m_layers = aOther.m_layers;
84  m_net = aOther.m_net;
85  m_movable = aOther.m_movable;
86  m_kind = aOther.m_kind;
87  m_parent = aOther.m_parent;
88  m_owner = NULL;
89  m_marker = aOther.m_marker;
90  m_rank = aOther.m_rank;
91  }
92 
93  virtual ~ITEM();
94 
100  virtual ITEM* Clone() const = 0;
101 
102  /*
103  * Function Hull()
104  *
105  * Returns a convex polygon "hull" of a the item, that is used as the walk-around
106  * path.
107  * @param aClearance defines how far from the body of the item the hull should be,
108  * @param aWalkaroundThickness is the width of the line that walks around this hull.
109  */
110  virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0 ) const
111  {
112  return SHAPE_LINE_CHAIN();
113  }
114 
120  PnsKind Kind() const
121  {
122  return m_kind;
123  }
124 
130  bool OfKind( int aKindMask ) const
131  {
132  return ( aKindMask & m_kind ) != 0;
133  }
134 
140  const std::string KindStr() const;
141 
148  {
149  m_parent = aParent;
150  }
151 
158  {
159  return m_parent;
160  }
161 
167  void SetNet( int aNet )
168  {
169  m_net = aNet;
170  }
171 
177  int Net() const
178  {
179  return m_net;
180  }
181 
187  void SetLayers( const LAYER_RANGE& aLayers )
188  {
189  m_layers = aLayers;
190  }
191 
197  void SetLayer( int aLayer )
198  {
199  m_layers = LAYER_RANGE( aLayer, aLayer );
200  }
201 
207  const LAYER_RANGE& Layers() const
208  {
209  return m_layers;
210  }
211 
217  virtual int Layer() const
218  {
219  return Layers().Start();
220  }
221 
228  bool LayersOverlap( const ITEM* aOther ) const
229  {
230  return Layers().Overlaps( aOther->Layers() );
231  }
232 
239  void SetOwner( NODE* aOwner )
240  {
241  m_owner = aOwner;
242  }
243 
249  bool BelongsTo( NODE* aNode ) const
250  {
251  return m_owner == aNode;
252  }
253 
259  NODE* Owner() const { return m_owner; }
260 
275  virtual bool Collide( const ITEM* aOther, int aClearance, bool aNeedMTV,
276  VECTOR2I& aMTV, bool aDifferentNetsOnly = true ) const;
277 
283  bool Collide( const ITEM* aOther, int aClearance, bool aDifferentNetsOnly = true ) const
284  {
285  VECTOR2I dummy;
286 
287  return Collide( aOther, aClearance, false, dummy, aDifferentNetsOnly );
288  }
289 
296  virtual const SHAPE* Shape() const
297  {
298  return NULL;
299  }
300 
301  virtual void Mark( int aMarker )
302  {
303  m_marker = aMarker;
304  }
305 
306  virtual void Unmark( int aMarker = -1 )
307  {
308  m_marker &= ~aMarker;
309  }
310 
311  virtual int Marker() const
312  {
313  return m_marker;
314  }
315 
316  virtual void SetRank( int aRank )
317  {
318  m_rank = aRank;
319  }
320 
321  virtual int Rank() const
322  {
323  return m_rank;
324  }
325 
326  virtual VECTOR2I Anchor( int n ) const
327  {
328  return VECTOR2I();
329  }
330 
331  virtual int AnchorCount() const
332  {
333  return 0;
334  }
335 
336  bool IsLocked() const
337  {
338  return Marker() & MK_LOCKED;
339  }
340 
341 private:
342  bool collideSimple( const ITEM* aOther, int aClearance, bool aNeedMTV,
343  VECTOR2I& aMTV, bool aDifferentNetsOnly ) const;
344 
345 protected:
347 
351 
352  bool m_movable;
353  int m_net;
354  int m_marker;
355  int m_rank;
356 };
357 
358 template< typename T, typename S >
359 std::unique_ptr< T > ItemCast( std::unique_ptr< S > aPtr )
360 {
361  static_assert(std::is_base_of< ITEM, S >::value, "Need to be handed a ITEM!");
362  static_assert(std::is_base_of< ITEM, T >::value, "Need to cast to an ITEM!");
363  return std::unique_ptr< T >( static_cast<T*>(aPtr.release()) );
364 }
365 
366 template< typename T >
367 std::unique_ptr< typename std::remove_const< T >::type > Clone( const T& aItem )
368 {
369  static_assert(std::is_base_of< ITEM, T >::value, "Need to be handed an ITEM!");
370  return std::unique_ptr< typename std::remove_const< T >::type >( aItem.Clone() );
371 }
372 
373 }
374 
375 #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:359
void SetOwner(NODE *aOwner)
Functon SetOwner()
Definition: pns_item.h:239
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:348
Class NODE.
Definition: pns_node.h:137
virtual int Layer() const
Function Layer()
Definition: pns_item.h:217
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:207
virtual ~ITEM()
Definition: pns_item.cpp:88
T
enum T contains all this lexer's tokens.
void SetLayer(int aLayer)
Function SetLayer()
Definition: pns_item.h:197
virtual void Unmark(int aMarker=-1)
Definition: pns_item.h:306
NODE * m_owner
Definition: pns_item.h:349
LAYER_RANGE m_layers
Definition: pns_item.h:350
bool BelongsTo(NODE *aNode) const
Function BelongsTo()
Definition: pns_item.h:249
int m_rank
Definition: pns_item.h:355
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:296
bool m_movable
Definition: pns_item.h:352
ITEM(PnsKind aKind)
Definition: pns_item.h:70
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0) const
Definition: pns_item.h:110
bool Collide(const ITEM *aOther, int aClearance, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.h:283
VECTOR2< int > VECTOR2I
Definition: vector2d.h:580
virtual int Marker() const
Definition: pns_item.h:311
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:354
void SetNet(int aNet)
Function SetNet()
Definition: pns_item.h:167
virtual bool Collide(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I &aMTV, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.cpp:44
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:130
void SetParent(BOARD_CONNECTED_ITEM *aParent)
Function SetParent()
Definition: pns_item.h:147
bool IsLocked() const
Definition: pns_item.h:336
virtual int Rank() const
Definition: pns_item.h:321
Class SHAPE.
Definition: shape.h:57
virtual int AnchorCount() const
Definition: pns_item.h:331
int Start() const
Definition: pns_layerset.h:83
virtual void SetRank(int aRank)
Definition: pns_item.h:316
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
NODE * Owner() const
Function Owner()
Definition: pns_item.h:259
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:187
int m_net
Definition: pns_item.h:353
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:120
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:367
PnsKind
Supported item types
Definition: pns_item.h:59
bool LayersOverlap(const ITEM *aOther) const
Function LayersOverlap()
Definition: pns_item.h:228
PnsKind m_kind
Definition: pns_item.h:346
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 collideSimple(const ITEM *aOther, int aClearance, bool aNeedMTV, VECTOR2I &aMTV, bool aDifferentNetsOnly) const
Definition: pns_item.cpp:27
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:326
int Net() const
Function Net()
Definition: pns_item.h:177
virtual void Mark(int aMarker)
Definition: pns_item.h:301
ITEM(const ITEM &aOther)
Definition: pns_item.h:81
Push and Shove diff pair dimensions (gap) settings dialog.
LineMarker
Definition: pns_item.h:39
BOARD_CONNECTED_ITEM * Parent() const
Function Parent()
Definition: pns_item.h:157
Class LAYER_RANGE.
Definition: pns_layerset.h:32
const std::string KindStr() const
Function KindStr()
Definition: pns_item.cpp:63