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 
189  void SetLayers( const LAYER_RANGE& aLayers )
190  {
191  m_layers = aLayers;
192  }
193 
199  void SetLayer( int aLayer )
200  {
201  m_layers = LAYER_RANGE( aLayer, aLayer );
202  }
203 
209  const LAYER_RANGE& Layers() const
210  {
211  return m_layers;
212  }
213 
219  virtual int Layer() const
220  {
221  return Layers().Start();
222  }
223 
230  bool LayersOverlap( const ITEM* aOther ) const
231  {
232  return Layers().Overlaps( aOther->Layers() );
233  }
234 
241  void SetOwner( NODE* aOwner )
242  {
243  m_owner = aOwner;
244  }
245 
251  bool BelongsTo( NODE* aNode ) const
252  {
253  return m_owner == aNode;
254  }
255 
261  NODE* Owner() const { return m_owner; }
262 
277  virtual bool Collide( const ITEM* aOther, int aClearance, bool aNeedMTV,
278  VECTOR2I& aMTV, bool aDifferentNetsOnly = true ) const;
279 
285  bool Collide( const ITEM* aOther, int aClearance, bool aDifferentNetsOnly = true ) const
286  {
287  VECTOR2I dummy;
288 
289  return Collide( aOther, aClearance, false, dummy, aDifferentNetsOnly );
290  }
291 
298  virtual const SHAPE* Shape() const
299  {
300  return NULL;
301  }
302 
303  virtual void Mark( int aMarker )
304  {
305  m_marker = aMarker;
306  }
307 
308  virtual void Unmark( int aMarker = -1 )
309  {
310  m_marker &= ~aMarker;
311  }
312 
313  virtual int Marker() const
314  {
315  return m_marker;
316  }
317 
318  virtual void SetRank( int aRank )
319  {
320  m_rank = aRank;
321  }
322 
323  virtual int Rank() const
324  {
325  return m_rank;
326  }
327 
328  virtual VECTOR2I Anchor( int n ) const
329  {
330  return VECTOR2I();
331  }
332 
333  virtual int AnchorCount() const
334  {
335  return 0;
336  }
337 
338  bool IsLocked() const
339  {
340  return Marker() & MK_LOCKED;
341  }
342 
343  void SetRoutable( bool aRoutable )
344  {
345  m_routable = aRoutable;
346  }
347 
348  bool IsRoutable() const
349  {
350  return m_routable;
351  }
352 
353 private:
354  bool collideSimple( const ITEM* aOther, int aClearance, bool aNeedMTV,
355  VECTOR2I& aMTV, bool aDifferentNetsOnly ) const;
356 
357 protected:
359 
363 
364  bool m_movable;
365  int m_net;
366  int m_marker;
367  int m_rank;
369 };
370 
371 template< typename T, typename S >
372 std::unique_ptr< T > ItemCast( std::unique_ptr< S > aPtr )
373 {
374  static_assert(std::is_base_of< ITEM, S >::value, "Need to be handed a ITEM!");
375  static_assert(std::is_base_of< ITEM, T >::value, "Need to cast to an ITEM!");
376  return std::unique_ptr< T >( static_cast<T*>(aPtr.release()) );
377 }
378 
379 template< typename T >
380 std::unique_ptr< typename std::remove_const< T >::type > Clone( const T& aItem )
381 {
382  static_assert(std::is_base_of< ITEM, T >::value, "Need to be handed an ITEM!");
383  return std::unique_ptr< typename std::remove_const< T >::type >( aItem.Clone() );
384 }
385 
386 }
387 
388 #endif // __PNS_ITEM_H
Class ITEM.
Definition: pns_item.h:53
bool IsRoutable() const
Definition: pns_item.h:348
virtual ITEM * Clone() const =0
Function Clone()
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:372
void SetOwner(NODE *aOwner)
Functon SetOwner()
Definition: pns_item.h:241
BOARD_CONNECTED_ITEM * m_parent
Definition: pns_item.h:360
Class NODE.
Definition: pns_node.h:137
virtual int Layer() const
Function Layer()
Definition: pns_item.h:219
const LAYER_RANGE & Layers() const
Function Layers()
Definition: pns_item.h:209
virtual ~ITEM()
Definition: pns_item.cpp:88
void SetLayer(int aLayer)
Function SetLayer()
Definition: pns_item.h:199
virtual void Unmark(int aMarker=-1)
Definition: pns_item.h:308
NODE * m_owner
Definition: pns_item.h:361
LAYER_RANGE m_layers
Definition: pns_item.h:362
bool BelongsTo(NODE *aNode) const
Function BelongsTo()
Definition: pns_item.h:251
int m_rank
Definition: pns_item.h:367
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:298
bool m_movable
Definition: pns_item.h:364
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:112
bool Collide(const ITEM *aOther, int aClearance, bool aDifferentNetsOnly=true) const
Function Collide()
Definition: pns_item.h:285
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
bool m_routable
Definition: pns_item.h:368
virtual int Marker() const
Definition: pns_item.h:313
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:366
void SetNet(int aNet)
Function SetNet()
Definition: pns_item.h:169
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:132
void SetParent(BOARD_CONNECTED_ITEM *aParent)
Function SetParent()
Definition: pns_item.h:149
bool IsLocked() const
Definition: pns_item.h:338
void SetRoutable(bool aRoutable)
Definition: pns_item.h:343
virtual int Rank() const
Definition: pns_item.h:323
Class SHAPE.
Definition: shape.h:58
virtual int AnchorCount() const
Definition: pns_item.h:333
int Start() const
Definition: pns_layerset.h:83
virtual void SetRank(int aRank)
Definition: pns_item.h:318
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
NODE * Owner() const
Function Owner()
Definition: pns_item.h:261
void SetLayers(const LAYER_RANGE &aLayers)
Function SetLayers()
Definition: pns_item.h:189
int m_net
Definition: pns_item.h:365
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122
PnsKind
Supported item types
Definition: pns_item.h:59
bool LayersOverlap(const ITEM *aOther) const
Function LayersOverlap()
Definition: pns_item.h:230
PnsKind m_kind
Definition: pns_item.h:358
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:328
int Net() const
Function Net()
Definition: pns_item.h:179
virtual void Mark(int aMarker)
Definition: pns_item.h:303
ITEM(const ITEM &aOther)
Definition: pns_item.h:82
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:159
Class LAYER_RANGE.
Definition: pns_layerset.h:32
const std::string KindStr() const
Function KindStr()
Definition: pns_item.cpp:63