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,
113 };
114
115 ITEM( PnsKind aKind )
116 {
117 m_net = nullptr;
118 m_movable = true;
119 m_kind = aKind;
120 m_parent = nullptr;
121 m_owner = nullptr;
122 m_marker = 0;
123 m_rank = -1;
124 m_routable = true;
125 m_isVirtual = false;
126 m_isFreePad = false;
128 }
129
130 ITEM( const ITEM& aOther )
131 {
132 m_layers = aOther.m_layers;
133 m_net = aOther.m_net;
134 m_movable = aOther.m_movable;
135 m_kind = aOther.m_kind;
136 m_parent = aOther.m_parent;
137 m_owner = nullptr;
138 m_marker = aOther.m_marker;
139 m_rank = aOther.m_rank;
140 m_routable = aOther.m_routable;
141 m_isVirtual = aOther.m_isVirtual;
142 m_isFreePad = aOther.m_isFreePad;
144 }
145
146 virtual ~ITEM();
147
151 virtual ITEM* Clone() const = 0;
152
153 /*
154 * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
155 *
156 * @param aClearance defines how far from the body of the item the hull should be,
157 * @param aWalkaroundThickness is the width of the line that walks around this hull.
158 * @param aLayer is the layer to build a hull for (the item may have different shapes on each
159 * layer). If aLayer is -1, the hull will be a merged hull from all layers.
160 */
161 virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
162 int aLayer = -1 ) const
163 {
164 return SHAPE_LINE_CHAIN();
165 }
166
170 PnsKind Kind() const
171 {
172 return m_kind;
173 }
174
178 bool OfKind( int aKindMask ) const
179 {
180 return ( aKindMask & m_kind ) != 0;
181 }
182
186 std::string KindStr() const;
187
188 void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
189 BOARD_ITEM* Parent() const { return m_parent; }
190
194 virtual BOARD_ITEM* BoardItem() const { return m_parent; }
195
196 void SetNet( NET_HANDLE aNet ) { m_net = aNet; }
197 virtual NET_HANDLE Net() const { return m_net; }
198
199 const PNS_LAYER_RANGE& Layers() const { return m_layers; }
200 void SetLayers( const PNS_LAYER_RANGE& aLayers ) { m_layers = aLayers; }
201
202 void SetLayer( int aLayer ) { m_layers = PNS_LAYER_RANGE( aLayer, aLayer ); }
203 virtual int Layer() const { return Layers().Start(); }
204
208 bool LayersOverlap( const ITEM* aOther ) const
209 {
210 return Layers().Overlaps( aOther->Layers() );
211 }
212
222 bool Collide( const ITEM* aHead, const NODE* aNode, int aLayer,
223 COLLISION_SEARCH_CONTEXT* aCtx = nullptr ) const;
224
229 virtual const SHAPE* Shape( int aLayer ) const
230 {
231 return nullptr;
232 }
233
237 virtual std::vector<int> UniqueShapeLayers() const { return { -1 }; }
238
239 virtual bool HasUniqueShapeLayers() const { return false; }
240
246 std::set<int> RelevantShapeLayers( const ITEM* aOther ) const;
247
248 virtual void Mark( int aMarker ) const { m_marker = aMarker; }
249 virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
250 virtual int Marker() const { return m_marker; }
251
252 virtual void SetRank( int aRank ) { m_rank = aRank; }
253 virtual int Rank() const { return m_rank; }
254
255 virtual VECTOR2I Anchor( int n ) const
256 {
257 return VECTOR2I();
258 }
259
260 virtual int AnchorCount() const
261 {
262 return 0;
263 }
264
265 bool IsLocked() const
266 {
267 return Marker() & MK_LOCKED;
268 }
269
270 void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
271 bool IsRoutable() const { return m_routable; }
272
273 void SetIsFreePad( bool aIsFreePad = true ) { m_isFreePad = aIsFreePad; }
274
275 bool IsFreePad() const
276 {
277 return m_isFreePad || ( ParentPadVia() && ParentPadVia()->m_isFreePad );
278 }
279
280 virtual ITEM* ParentPadVia() const { return nullptr; }
281
282 bool IsVirtual() const
283 {
284 return m_isVirtual;
285 }
286
289
290 virtual bool HasHole() const { return false; }
291 virtual HOLE *Hole() const { return nullptr; }
292 virtual void SetHole( HOLE* aHole ) {};
293
294 virtual const std::string Format() const;
295
296 virtual const NODE* OwningNode() const;
297
298private:
299 bool collideSimple( const ITEM* aHead, const NODE* aNode, int aLayer,
300 COLLISION_SEARCH_CONTEXT* aCtx ) const;
301
302protected:
304
307
310 mutable int m_marker;
316};
317
318template<typename T, typename S>
319std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
320{
321 static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
322 static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
323 return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
324}
325
326template<typename T>
327std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
328{
329 static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
330 return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
331}
332
333}
334
335#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:58
Base class for PNS router board items.
Definition: pns_item.h:97
BOARD_ITEM * Parent() const
Definition: pns_item.h:189
bool IsFreePad() const
Definition: pns_item.h:275
PnsKind m_kind
Definition: pns_item.h:303
virtual bool HasUniqueShapeLayers() const
Definition: pns_item.h:239
void SetLayers(const PNS_LAYER_RANGE &aLayers)
Definition: pns_item.h:200
void SetIsFreePad(bool aIsFreePad=true)
Definition: pns_item.h:273
virtual const std::string Format() const
Definition: pns_item.cpp:329
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:249
virtual int Rank() const
Definition: pns_item.h:253
bool m_isVirtual
Definition: pns_item.h:313
virtual ITEM * ParentPadVia() const
Definition: pns_item.h:280
virtual std::vector< int > UniqueShapeLayers() const
Return a list of layers that have unique (potentially different) shapes.
Definition: pns_item.h:237
virtual const SHAPE * Shape(int aLayer) const
Return the geometrical shape of the item.
Definition: pns_item.h:229
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:199
bool m_movable
Definition: pns_item.h:308
ITEM(const ITEM &aOther)
Definition: pns_item.h:130
ITEM(PnsKind aKind)
Definition: pns_item.h:115
virtual NET_HANDLE Net() const
Definition: pns_item.h:197
virtual void SetHole(HOLE *aHole)
Definition: pns_item.h:292
PNS_LAYER_RANGE m_layers
Definition: pns_item.h:306
bool m_routable
Definition: pns_item.h:312
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:170
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:196
virtual void SetRank(int aRank)
Definition: pns_item.h:252
NET_HANDLE m_net
Definition: pns_item.h:309
virtual int Layer() const
Definition: pns_item.h:203
void SetLayer(int aLayer)
Definition: pns_item.h:202
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:287
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
@ LINKED_ITEM_MASK_T
Definition: pns_item.h:112
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:188
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:296
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:314
virtual ~ITEM()
Definition: pns_item.cpp:324
virtual const NODE * OwningNode() const
Definition: pns_item.cpp:345
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:288
int m_marker
Definition: pns_item.h:310
bool OfKind(int aKindMask) const
Definition: pns_item.h:178
bool IsVirtual() const
Definition: pns_item.h:282
bool IsRoutable() const
Definition: pns_item.h:271
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:255
std::string KindStr() const
Definition: pns_item.cpp:306
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:208
bool m_isCompoundShapePrimitive
Definition: pns_item.h:315
virtual HOLE * Hole() const
Definition: pns_item.h:291
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:161
virtual void Mark(int aMarker) const
Definition: pns_item.h:248
virtual int AnchorCount() const
Definition: pns_item.h:260
virtual bool HasHole() const
Definition: pns_item.h:290
virtual BOARD_ITEM * BoardItem() const
Definition: pns_item.h:194
void SetRoutable(bool aRoutable)
Definition: pns_item.h:270
bool IsLocked() const
Definition: pns_item.h:265
virtual int Marker() const
Definition: pns_item.h:250
BOARD_ITEM * m_parent
Definition: pns_item.h:305
int m_rank
Definition: pns_item.h:311
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: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 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:319
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:327
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691