KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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 <set>
28#include <unordered_set>
29#include <math/vector2d.h>
30
31#include <geometry/shape.h>
33
34#include "pns_layerset.h"
35
36class BOARD_ITEM;
37
38namespace PNS {
39
40class NODE;
41
43 MK_HEAD = ( 1 << 0 ),
44 MK_VIOLATION = ( 1 << 3 ),
45 MK_LOCKED = ( 1 << 4 ),
46 MK_DP_COUPLED = ( 1 << 5 )
47};
48
49
50class ITEM;
51class HOLE;
52struct COLLISION_SEARCH_CONTEXT;
53
54// An opaque net identifier. The internal workings are owned by the ROUTER_IFACE.
55typedef void* NET_HANDLE;
56
58public:
59 virtual ~ITEM_OWNER() {};
60};
61
63{
64public:
66 m_owner( nullptr )
67 {}
68
72 const ITEM_OWNER* Owner() const { return m_owner; }
73
77 void SetOwner( const ITEM_OWNER* aOwner ) { m_owner = aOwner; }
78
82 bool BelongsTo( const ITEM_OWNER* aNode ) const
83 {
84 return m_owner == aNode;
85 }
86
87protected:
89};
90
97class ITEM : public OWNABLE_ITEM, public ITEM_OWNER
98{
99public:
102 {
108 ARC_T = 16,
109 VIA_T = 32,
111 HOLE_T = 128,
112 ANY_T = 0xffff,
114 };
115
116 ITEM( PnsKind aKind )
117 {
118 m_net = nullptr;
119 m_movable = true;
120 m_kind = aKind;
121 m_parent = nullptr;
122 m_owner = nullptr;
123 m_marker = 0;
124 m_rank = -1;
125 m_routable = true;
126 m_isVirtual = false;
127 m_isFreePad = false;
129 }
130
131 ITEM( const ITEM& aOther )
132 {
133 m_layers = aOther.m_layers;
134 m_net = aOther.m_net;
135 m_movable = aOther.m_movable;
136 m_kind = aOther.m_kind;
137 m_parent = aOther.m_parent;
138 m_owner = nullptr;
139 m_marker = aOther.m_marker;
140 m_rank = aOther.m_rank;
141 m_routable = aOther.m_routable;
142 m_isVirtual = aOther.m_isVirtual;
143 m_isFreePad = aOther.m_isFreePad;
145 }
146
147 virtual ~ITEM();
148
152 virtual ITEM* Clone() const = 0;
153
154 /*
155 * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
156 *
157 * @param aClearance defines how far from the body of the item the hull should be,
158 * @param aWalkaroundThickness is the width of the line that walks around this hull.
159 * @param aLayer is the layer to build a hull for (the item may have different shapes on each
160 * layer). If aLayer is -1, the hull will be a merged hull from all layers.
161 */
162 virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
163 int aLayer = -1 ) const
164 {
165 return SHAPE_LINE_CHAIN();
166 }
167
171 PnsKind Kind() const
172 {
173 return m_kind;
174 }
175
179 bool OfKind( int aKindMask ) const
180 {
181 return ( aKindMask & m_kind ) != 0;
182 }
183
187 std::string KindStr() const;
188
189 void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
190 BOARD_ITEM* Parent() const { return m_parent; }
191
195 virtual BOARD_ITEM* BoardItem() const { return m_parent; }
196
197 void SetNet( NET_HANDLE aNet ) { m_net = aNet; }
198 virtual NET_HANDLE Net() const { return m_net; }
199
200 const PNS_LAYER_RANGE& Layers() const { return m_layers; }
201 void SetLayers( const PNS_LAYER_RANGE& aLayers ) { m_layers = aLayers; }
202
203 void SetLayer( int aLayer ) { m_layers = PNS_LAYER_RANGE( aLayer, aLayer ); }
204 virtual int Layer() const { return Layers().Start(); }
205
209 bool LayersOverlap( const ITEM* aOther ) const
210 {
211 return Layers().Overlaps( aOther->Layers() );
212 }
213
223 bool Collide( const ITEM* aHead, const NODE* aNode, int aLayer,
224 COLLISION_SEARCH_CONTEXT* aCtx = nullptr ) const;
225
230 virtual const SHAPE* Shape( int aLayer ) const
231 {
232 return nullptr;
233 }
234
238 virtual std::vector<int> UniqueShapeLayers() const { return { -1 }; }
239
240 virtual bool HasUniqueShapeLayers() const { return false; }
241
247 std::set<int> RelevantShapeLayers( const ITEM* aOther ) const;
248
249 virtual void Mark( int aMarker ) const { m_marker = aMarker; }
250 virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
251 virtual int Marker() const { return m_marker; }
252
253 virtual void SetRank( int aRank ) { m_rank = aRank; }
254 virtual int Rank() const { return m_rank; }
255
256 virtual VECTOR2I Anchor( int n ) const
257 {
258 return VECTOR2I();
259 }
260
261 virtual int AnchorCount() const
262 {
263 return 0;
264 }
265
266 bool IsLocked() const
267 {
268 return Marker() & MK_LOCKED;
269 }
270
271 void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
272 bool IsRoutable() const { return m_routable; }
273
274 void SetIsFreePad( bool aIsFreePad = true ) { m_isFreePad = aIsFreePad; }
275
276 bool IsFreePad() const
277 {
278 return m_isFreePad || ( ParentPadVia() && ParentPadVia()->m_isFreePad );
279 }
280
281 virtual ITEM* ParentPadVia() const { return nullptr; }
282
283 bool IsVirtual() const
284 {
285 return m_isVirtual;
286 }
287
290
291 virtual bool HasHole() const { return false; }
292 virtual HOLE *Hole() const { return nullptr; }
293 virtual void SetHole( HOLE* aHole ) {};
294
295 virtual const std::string Format() const;
296
297 virtual const NODE* OwningNode() const;
298
299private:
300 bool collideSimple( const ITEM* aHead, const NODE* aNode, int aLayer,
301 COLLISION_SEARCH_CONTEXT* aCtx ) const;
302
303protected:
305
308
311 mutable int m_marker;
317};
318
319template<typename T, typename S>
320std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
321{
322 static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
323 static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
324 return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
325}
326
327template<typename T>
328std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
329{
330 static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
331 return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
332}
333
334}
335
336#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:79
virtual ~ITEM_OWNER()
Definition: pns_item.h:59
Base class for PNS router board items.
Definition: pns_item.h:98
BOARD_ITEM * Parent() const
Definition: pns_item.h:190
bool IsFreePad() const
Definition: pns_item.h:276
PnsKind m_kind
Definition: pns_item.h:304
virtual bool HasUniqueShapeLayers() const
Definition: pns_item.h:240
void SetLayers(const PNS_LAYER_RANGE &aLayers)
Definition: pns_item.h:201
void SetIsFreePad(bool aIsFreePad=true)
Definition: pns_item.h:274
virtual const std::string Format() const
Definition: pns_item.cpp:335
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:250
virtual int Rank() const
Definition: pns_item.h:254
bool m_isVirtual
Definition: pns_item.h:314
virtual ITEM * ParentPadVia() const
Definition: pns_item.h:281
virtual std::vector< int > UniqueShapeLayers() const
Return a list of layers that have unique (potentially different) shapes.
Definition: pns_item.h:238
virtual const SHAPE * Shape(int aLayer) const
Return the geometrical shape of the item.
Definition: pns_item.h:230
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:200
bool m_movable
Definition: pns_item.h:309
ITEM(const ITEM &aOther)
Definition: pns_item.h:131
ITEM(PnsKind aKind)
Definition: pns_item.h:116
virtual NET_HANDLE Net() const
Definition: pns_item.h:198
virtual void SetHole(HOLE *aHole)
Definition: pns_item.h:293
PNS_LAYER_RANGE m_layers
Definition: pns_item.h:307
bool m_routable
Definition: pns_item.h:313
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:171
virtual ITEM * Clone() const =0
Return a deep copy of the item.
std::set< int > RelevantShapeLayers(const ITEM *aOther) const
Returns the set of layers on which either this or the other item can have a unique shape.
Definition: pns_item.cpp:94
void SetNet(NET_HANDLE aNet)
Definition: pns_item.h:197
virtual void SetRank(int aRank)
Definition: pns_item.h:253
NET_HANDLE m_net
Definition: pns_item.h:310
virtual int Layer() const
Definition: pns_item.h:204
void SetLayer(int aLayer)
Definition: pns_item.h:203
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:288
PnsKind
< Supported item types
Definition: pns_item.h:102
@ INVALID_T
Definition: pns_item.h:103
@ SEGMENT_T
Definition: pns_item.h:107
@ DIFF_PAIR_T
Definition: pns_item.h:110
@ LINKED_ITEM_MASK_T
Definition: pns_item.h:113
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:189
bool Collide(const ITEM *aHead, const NODE *aNode, int aLayer, COLLISION_SEARCH_CONTEXT *aCtx=nullptr) const
Check for a collision (clearance violation) with between us and item aOther.
Definition: pns_item.cpp:302
bool collideSimple(const ITEM *aHead, const NODE *aNode, int aLayer, COLLISION_SEARCH_CONTEXT *aCtx) const
Definition: pns_item.cpp:115
bool m_isFreePad
Definition: pns_item.h:315
virtual ~ITEM()
Definition: pns_item.cpp:330
virtual const NODE * OwningNode() const
Definition: pns_item.cpp:351
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:289
int m_marker
Definition: pns_item.h:311
bool OfKind(int aKindMask) const
Definition: pns_item.h:179
bool IsVirtual() const
Definition: pns_item.h:283
bool IsRoutable() const
Definition: pns_item.h:272
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:256
std::string KindStr() const
Definition: pns_item.cpp:312
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:209
bool m_isCompoundShapePrimitive
Definition: pns_item.h:316
virtual HOLE * Hole() const
Definition: pns_item.h:292
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:162
virtual void Mark(int aMarker) const
Definition: pns_item.h:249
virtual int AnchorCount() const
Definition: pns_item.h:261
virtual bool HasHole() const
Definition: pns_item.h:291
virtual BOARD_ITEM * BoardItem() const
Definition: pns_item.h:195
void SetRoutable(bool aRoutable)
Definition: pns_item.h:271
bool IsLocked() const
Definition: pns_item.h:266
virtual int Marker() const
Definition: pns_item.h:251
BOARD_ITEM * m_parent
Definition: pns_item.h:306
int m_rank
Definition: pns_item.h:312
Keep the router "world" - i.e.
Definition: pns_node.h:231
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition: pns_item.h:77
const ITEM_OWNER * m_owner
Definition: pns_item.h:88
bool BelongsTo(const ITEM_OWNER *aNode) const
Definition: pns_item.h:82
const ITEM_OWNER * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:72
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
int Start() const
Definition: pns_layerset.h:86
bool Overlaps(const PNS_LAYER_RANGE &aOther) const
Definition: pns_layerset.h:67
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:126
Push and Shove diff pair dimensions (gap) settings dialog.
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:320
void * NET_HANDLE
Definition: pns_item.h:55
LineMarker
Definition: pns_item.h:42
@ MK_VIOLATION
Definition: pns_item.h:44
@ MK_DP_COUPLED
Definition: pns_item.h:46
@ MK_HEAD
Definition: pns_item.h:43
@ MK_LOCKED
Definition: pns_item.h:45
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:328
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695