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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef __PNS_ITEM_H
24#define __PNS_ITEM_H
25
26#include <memory>
27#include <math/vector2d.h>
28
29#include <geometry/shape.h>
31
32#include "pns_layerset.h"
33
34class BOARD_ITEM;
35
36namespace PNS {
37
38class NODE;
39
41 MK_HEAD = ( 1 << 0 ),
42 MK_VIOLATION = ( 1 << 3 ),
43 MK_LOCKED = ( 1 << 4 ),
44 MK_DP_COUPLED = ( 1 << 5 ),
45 MK_HOLE = ( 1 << 6 )
46};
47
48
55class ITEM
56{
57public:
58 static const int UnusedNet = INT_MAX;
59
62 {
64 LINE_T = 2,
67 ARC_T = 16,
68 VIA_T = 32,
70 ANY_T = 0xff
71 };
72
73 ITEM( PnsKind aKind )
74 {
76 m_movable = true;
77 m_kind = aKind;
78 m_parent = nullptr;
79 m_owner = nullptr;
80 m_marker = 0;
81 m_rank = -1;
82 m_routable = true;
83 m_isVirtual = false;
84 m_isFreePad = false;
86 }
87
88 ITEM( const ITEM& aOther )
89 {
90 m_layers = aOther.m_layers;
91 m_net = aOther.m_net;
92 m_movable = aOther.m_movable;
93 m_kind = aOther.m_kind;
94 m_parent = aOther.m_parent;
95 m_owner = aOther.m_owner; // fixme: wtf this was null?
96 m_marker = aOther.m_marker;
97 m_rank = aOther.m_rank;
98 m_routable = aOther.m_routable;
99 m_isVirtual = aOther.m_isVirtual;
100 m_isFreePad = aOther.m_isFreePad;
102 }
103
104 virtual ~ITEM();
105
109 virtual ITEM* Clone() const = 0;
110
111 /*
112 * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
113 *
114 * @param aClearance defines how far from the body of the item the hull should be,
115 * @param aWalkaroundThickness is the width of the line that walks around this hull.
116 */
117 virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
118 int aLayer = -1 ) const
119 {
120 return SHAPE_LINE_CHAIN();
121 }
122
123 virtual const SHAPE_LINE_CHAIN HoleHull( int aClearance, int aWalkaroundThickness = 0,
124 int aLayer = -1 ) const
125 {
126 return SHAPE_LINE_CHAIN();
127 }
128
132 PnsKind Kind() const
133 {
134 return m_kind;
135 }
136
140 bool OfKind( int aKindMask ) const
141 {
142 return ( aKindMask & m_kind ) != 0;
143 }
144
148 std::string KindStr() const;
149
150 void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
151 BOARD_ITEM* Parent() const { return m_parent; }
152
153 void SetNet( int aNet ) { m_net = aNet; }
154 int Net() const { return m_net; }
155
156 const LAYER_RANGE& Layers() const { return m_layers; }
157 void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
158
159 void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
160 virtual int Layer() const { return Layers().Start(); }
161
165 bool LayersOverlap( const ITEM* aOther ) const
166 {
167 return Layers().Overlaps( aOther->Layers() );
168 }
169
173 NODE* Owner() const { return m_owner; }
174
178 void SetOwner( NODE* aOwner ) { m_owner = aOwner; }
179
183 bool BelongsTo( NODE* aNode ) const
184 {
185 return m_owner == aNode;
186 }
187
197 bool Collide( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly = true, int aOverrideClearance = -1 ) const;
198
202 virtual const SHAPE* Shape() const
203 {
204 return nullptr;
205 }
206
207 virtual const SHAPE* Hole() const
208 {
209 return nullptr;
210 }
211
212 virtual void Mark( int aMarker ) const { m_marker = aMarker; }
213 virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
214 virtual int Marker() const { return m_marker; }
215
216 virtual void SetRank( int aRank ) { m_rank = aRank; }
217 virtual int Rank() const { return m_rank; }
218
219 virtual VECTOR2I Anchor( int n ) const
220 {
221 return VECTOR2I();
222 }
223
224 virtual int AnchorCount() const
225 {
226 return 0;
227 }
228
229 bool IsLocked() const
230 {
231 return Marker() & MK_LOCKED;
232 }
233
234 void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
235 bool IsRoutable() const { return m_routable; }
236
237 void SetIsFreePad( bool aIsFreePad = true ) { m_isFreePad = aIsFreePad; }
238 bool IsFreePad() const { return m_isFreePad; }
239
240 bool IsVirtual() const
241 {
242 return m_isVirtual;
243 }
244
247
248private:
249 bool collideSimple( const ITEM* aOther, const NODE* aNode, bool aDifferentNetsOnly, int aOverrideClearance ) const;
250
251protected:
253
257
259 int m_net;
260 mutable int m_marker;
266};
267
268template<typename T, typename S>
269std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
270{
271 static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
272 static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
273 return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
274}
275
276template<typename T>
277std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
278{
279 static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
280 return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
281}
282
283}
284
285#endif // __PNS_ITEM_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:50
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
int Start() const
Definition: pns_layerset.h:82
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
Base class for PNS router board items.
Definition: pns_item.h:56
BOARD_ITEM * Parent() const
Definition: pns_item.h:151
bool IsFreePad() const
Definition: pns_item.h:238
PnsKind m_kind
Definition: pns_item.h:252
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:157
void SetIsFreePad(bool aIsFreePad=true)
Definition: pns_item.h:237
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:213
virtual int Rank() const
Definition: pns_item.h:217
int m_net
Definition: pns_item.h:259
bool m_isVirtual
Definition: pns_item.h:263
virtual const SHAPE_LINE_CHAIN HoleHull(int aClearance, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:123
bool m_movable
Definition: pns_item.h:258
ITEM(const ITEM &aOther)
Definition: pns_item.h:88
ITEM(PnsKind aKind)
Definition: pns_item.h:73
void SetOwner(NODE *aOwner)
Set the node that owns this item.
Definition: pns_item.h:178
bool Collide(const ITEM *aOther, const NODE *aNode, bool aDifferentNetsOnly=true, int aOverrideClearance=-1) const
Check for a collision (clearance violation) with between us and item aOther.
Definition: pns_item.cpp:169
virtual const SHAPE * Hole() const
Definition: pns_item.h:207
void SetNet(int aNet)
Definition: pns_item.h:153
bool m_routable
Definition: pns_item.h:262
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:132
virtual ITEM * Clone() const =0
Return a deep copy of the item.
NODE * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:173
virtual void SetRank(int aRank)
Definition: pns_item.h:216
bool BelongsTo(NODE *aNode) const
Definition: pns_item.h:183
LAYER_RANGE m_layers
Definition: pns_item.h:256
virtual int Layer() const
Definition: pns_item.h:160
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:202
void SetLayer(int aLayer)
Definition: pns_item.h:159
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:245
@ SOLID_T
Definition: pns_item.h:63
@ LINE_T
Definition: pns_item.h:64
@ SEGMENT_T
Definition: pns_item.h:66
@ DIFF_PAIR_T
Definition: pns_item.h:69
@ JOINT_T
Definition: pns_item.h:65
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:150
const LAYER_RANGE & Layers() const
Definition: pns_item.h:156
bool m_isFreePad
Definition: pns_item.h:264
virtual ~ITEM()
Definition: pns_item.cpp:214
static const int UnusedNet
Supported item types.
Definition: pns_item.h:58
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:246
int m_marker
Definition: pns_item.h:260
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:140
bool collideSimple(const ITEM *aOther, const NODE *aNode, bool aDifferentNetsOnly, int aOverrideClearance) const
Definition: pns_item.cpp:32
bool IsVirtual() const
Definition: pns_item.h:240
bool IsRoutable() const
Definition: pns_item.h:235
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:219
NODE * m_owner
Definition: pns_item.h:255
std::string KindStr() const
Returns the kind of the item, as string.
Definition: pns_item.cpp:198
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:165
bool m_isCompoundShapePrimitive
Definition: pns_item.h:265
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:117
virtual void Mark(int aMarker) const
Definition: pns_item.h:212
virtual int AnchorCount() const
Definition: pns_item.h:224
void SetRoutable(bool aRoutable)
Definition: pns_item.h:234
int Net() const
Definition: pns_item.h:154
bool IsLocked() const
Definition: pns_item.h:229
virtual int Marker() const
Definition: pns_item.h:214
BOARD_ITEM * m_parent
Definition: pns_item.h:254
int m_rank
Definition: pns_item.h:261
Keep the router "world" - i.e.
Definition: pns_node.h:155
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
An abstract shape on 2D plane.
Definition: shape.h:123
Push and Shove diff pair dimensions (gap) settings dialog.
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:269
LineMarker
Definition: pns_item.h:40
@ MK_VIOLATION
Definition: pns_item.h:42
@ MK_DP_COUPLED
Definition: pns_item.h:44
@ MK_HEAD
Definition: pns_item.h:41
@ MK_LOCKED
Definition: pns_item.h:43
@ MK_HOLE
Definition: pns_item.h:45
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:277
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618