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 (C) 2016-2023 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 <unordered_set>
28#include <math/vector2d.h>
29
30#include <geometry/shape.h>
32
33#include "pns_layerset.h"
34
35class BOARD_ITEM;
36
37namespace PNS {
38
39class NODE;
40
42 MK_HEAD = ( 1 << 0 ),
43 MK_VIOLATION = ( 1 << 3 ),
44 MK_LOCKED = ( 1 << 4 ),
45 MK_DP_COUPLED = ( 1 << 5 )
46};
47
48
49class ITEM;
50class HOLE;
51struct COLLISION_SEARCH_CONTEXT;
52
53// An opaque net identifier. The internal workings are owned by the ROUTER_IFACE.
54typedef void* NET_HANDLE;
55
57public:
58 virtual ~ITEM_OWNER() {};
59};
60
62{
63public:
65 m_owner( nullptr )
66 {}
67
71 const ITEM_OWNER* Owner() const { return m_owner; }
72
76 void SetOwner( const ITEM_OWNER* aOwner ) { m_owner = aOwner; }
77
81 bool BelongsTo( const ITEM_OWNER* aNode ) const
82 {
83 return m_owner == aNode;
84 }
85
86protected:
88};
89
96class ITEM : public OWNABLE_ITEM, public ITEM_OWNER
97{
98public:
101 {
107 ARC_T = 16,
108 VIA_T = 32,
110 HOLE_T = 128,
111 ANY_T = 0xffff
112 };
113
114 ITEM( PnsKind aKind )
115 {
116 m_net = nullptr;
117 m_movable = true;
118 m_kind = aKind;
119 m_parent = nullptr;
120 m_owner = nullptr;
121 m_marker = 0;
122 m_rank = -1;
123 m_routable = true;
124 m_isVirtual = false;
125 m_isFreePad = false;
127 }
128
129 ITEM( const ITEM& aOther )
130 {
131 m_layers = aOther.m_layers;
132 m_net = aOther.m_net;
133 m_movable = aOther.m_movable;
134 m_kind = aOther.m_kind;
135 m_parent = aOther.m_parent;
136 m_owner = nullptr;
137 m_marker = aOther.m_marker;
138 m_rank = aOther.m_rank;
139 m_routable = aOther.m_routable;
140 m_isVirtual = aOther.m_isVirtual;
141 m_isFreePad = aOther.m_isFreePad;
143 }
144
145 virtual ~ITEM();
146
150 virtual ITEM* Clone() const = 0;
151
152 /*
153 * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
154 *
155 * @param aClearance defines how far from the body of the item the hull should be,
156 * @param aWalkaroundThickness is the width of the line that walks around this hull.
157 */
158 virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
159 int aLayer = -1 ) const
160 {
161 return SHAPE_LINE_CHAIN();
162 }
163
167 PnsKind Kind() const
168 {
169 return m_kind;
170 }
171
175 bool OfKind( int aKindMask ) const
176 {
177 return ( aKindMask & m_kind ) != 0;
178 }
179
183 std::string KindStr() const;
184
185 void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
186 BOARD_ITEM* Parent() const { return m_parent; }
187
191 virtual BOARD_ITEM* BoardItem() const { return m_parent; }
192
193 void SetNet( NET_HANDLE aNet ) { m_net = aNet; }
194 virtual NET_HANDLE Net() const { return m_net; }
195
196 const LAYER_RANGE& Layers() const { return m_layers; }
197 void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
198
199 void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
200 virtual int Layer() const { return Layers().Start(); }
201
205 bool LayersOverlap( const ITEM* aOther ) const
206 {
207 return Layers().Overlaps( aOther->Layers() );
208 }
209
219 bool Collide( const ITEM* aHead, const NODE* aNode,
220 COLLISION_SEARCH_CONTEXT* aCtx = nullptr ) const;
221
225 virtual const SHAPE* Shape() const
226 {
227 return nullptr;
228 }
229
230 virtual void Mark( int aMarker ) const { m_marker = aMarker; }
231 virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
232 virtual int Marker() const { return m_marker; }
233
234 virtual void SetRank( int aRank ) { m_rank = aRank; }
235 virtual int Rank() const { return m_rank; }
236
237 virtual VECTOR2I Anchor( int n ) const
238 {
239 return VECTOR2I();
240 }
241
242 virtual int AnchorCount() const
243 {
244 return 0;
245 }
246
247 bool IsLocked() const
248 {
249 return Marker() & MK_LOCKED;
250 }
251
252 void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
253 bool IsRoutable() const { return m_routable; }
254
255 void SetIsFreePad( bool aIsFreePad = true ) { m_isFreePad = aIsFreePad; }
256
257 bool IsFreePad() const
258 {
259 return m_isFreePad || ( ParentPadVia() && ParentPadVia()->m_isFreePad );
260 }
261
262 virtual ITEM* ParentPadVia() const { return nullptr; }
263
264 bool IsVirtual() const
265 {
266 return m_isVirtual;
267 }
268
271
272 virtual bool HasHole() const { return false; }
273 virtual HOLE *Hole() const { return nullptr; }
274 virtual void SetHole( HOLE* aHole ) {};
275
276 virtual const std::string Format() const;
277
278 virtual const NODE* OwningNode() const;
279
280private:
281 bool collideSimple( const ITEM* aHead, const NODE* aNode,
282 COLLISION_SEARCH_CONTEXT* aCtx ) const;
283
284protected:
286
289
292 mutable int m_marker;
298};
299
300template<typename T, typename S>
301std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
302{
303 static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
304 static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
305 return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
306}
307
308template<typename T>
309std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
310{
311 static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
312 return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
313}
314
315}
316
317#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:77
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
virtual ~ITEM_OWNER()
Definition: pns_item.h:58
Base class for PNS router board items.
Definition: pns_item.h:97
BOARD_ITEM * Parent() const
Definition: pns_item.h:186
bool IsFreePad() const
Definition: pns_item.h:257
PnsKind m_kind
Definition: pns_item.h:285
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:197
void SetIsFreePad(bool aIsFreePad=true)
Definition: pns_item.h:255
virtual const std::string Format() const
Definition: pns_item.cpp:305
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:231
virtual int Rank() const
Definition: pns_item.h:235
bool m_isVirtual
Definition: pns_item.h:295
virtual ITEM * ParentPadVia() const
Definition: pns_item.h:262
bool m_movable
Definition: pns_item.h:290
ITEM(const ITEM &aOther)
Definition: pns_item.h:129
ITEM(PnsKind aKind)
Definition: pns_item.h:114
virtual NET_HANDLE Net() const
Definition: pns_item.h:194
virtual void SetHole(HOLE *aHole)
Definition: pns_item.h:274
bool m_routable
Definition: pns_item.h:294
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:167
virtual ITEM * Clone() const =0
Return a deep copy of the item.
void SetNet(NET_HANDLE aNet)
Definition: pns_item.h:193
virtual void SetRank(int aRank)
Definition: pns_item.h:234
LAYER_RANGE m_layers
Definition: pns_item.h:288
NET_HANDLE m_net
Definition: pns_item.h:291
virtual int Layer() const
Definition: pns_item.h:200
bool collideSimple(const ITEM *aHead, const NODE *aNode, COLLISION_SEARCH_CONTEXT *aCtx) const
Definition: pns_item.cpp:93
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:225
void SetLayer(int aLayer)
Definition: pns_item.h:199
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:269
PnsKind
< Supported item types
Definition: pns_item.h:101
@ INVALID_T
Definition: pns_item.h:102
@ SEGMENT_T
Definition: pns_item.h:106
@ DIFF_PAIR_T
Definition: pns_item.h:109
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:185
const LAYER_RANGE & Layers() const
Definition: pns_item.h:196
bool m_isFreePad
Definition: pns_item.h:296
virtual ~ITEM()
Definition: pns_item.cpp:300
virtual const NODE * OwningNode() const
Definition: pns_item.cpp:321
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:270
int m_marker
Definition: pns_item.h:292
bool OfKind(int aKindMask) const
Definition: pns_item.h:175
bool IsVirtual() const
Definition: pns_item.h:264
bool IsRoutable() const
Definition: pns_item.h:253
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:237
std::string KindStr() const
Definition: pns_item.cpp:282
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:205
bool m_isCompoundShapePrimitive
Definition: pns_item.h:297
virtual HOLE * Hole() const
Definition: pns_item.h:273
bool Collide(const ITEM *aHead, const NODE *aNode, COLLISION_SEARCH_CONTEXT *aCtx=nullptr) const
Check for a collision (clearance violation) with between us and item aOther.
Definition: pns_item.cpp:273
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:158
virtual void Mark(int aMarker) const
Definition: pns_item.h:230
virtual int AnchorCount() const
Definition: pns_item.h:242
virtual bool HasHole() const
Definition: pns_item.h:272
virtual BOARD_ITEM * BoardItem() const
Definition: pns_item.h:191
void SetRoutable(bool aRoutable)
Definition: pns_item.h:252
bool IsLocked() const
Definition: pns_item.h:247
virtual int Marker() const
Definition: pns_item.h:232
BOARD_ITEM * m_parent
Definition: pns_item.h:287
int m_rank
Definition: pns_item.h:293
Keep the router "world" - i.e.
Definition: pns_node.h:207
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition: pns_item.h:76
const ITEM_OWNER * m_owner
Definition: pns_item.h:87
bool BelongsTo(const ITEM_OWNER *aNode) const
Definition: pns_item.h:81
const ITEM_OWNER * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:71
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:301
void * NET_HANDLE
Definition: pns_item.h:54
LineMarker
Definition: pns_item.h:41
@ MK_VIOLATION
Definition: pns_item.h:43
@ MK_DP_COUPLED
Definition: pns_item.h:45
@ MK_HEAD
Definition: pns_item.h:42
@ MK_LOCKED
Definition: pns_item.h:44
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition: pns_item.h:309
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602