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 {
106 ARC_T = 16,
107 VIA_T = 32,
109 HOLE_T = 128,
110 ANY_T = 0xffff
111 };
112
113 ITEM( PnsKind aKind )
114 {
115 m_net = nullptr;
116 m_movable = true;
117 m_kind = aKind;
118 m_parent = nullptr;
119 m_owner = nullptr;
120 m_marker = 0;
121 m_rank = -1;
122 m_routable = true;
123 m_isVirtual = false;
124 m_isFreePad = false;
126 }
127
128 ITEM( const ITEM& aOther )
129 {
130 m_layers = aOther.m_layers;
131 m_net = aOther.m_net;
132 m_movable = aOther.m_movable;
133 m_kind = aOther.m_kind;
134 m_parent = aOther.m_parent;
135 m_owner = nullptr;
136 m_marker = aOther.m_marker;
137 m_rank = aOther.m_rank;
138 m_routable = aOther.m_routable;
139 m_isVirtual = aOther.m_isVirtual;
140 m_isFreePad = aOther.m_isFreePad;
142 }
143
144 virtual ~ITEM();
145
149 virtual ITEM* Clone() const = 0;
150
151 /*
152 * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
153 *
154 * @param aClearance defines how far from the body of the item the hull should be,
155 * @param aWalkaroundThickness is the width of the line that walks around this hull.
156 */
157 virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
158 int aLayer = -1 ) const
159 {
160 return SHAPE_LINE_CHAIN();
161 }
162
166 PnsKind Kind() const
167 {
168 return m_kind;
169 }
170
174 bool OfKind( int aKindMask ) const
175 {
176 return ( aKindMask & m_kind ) != 0;
177 }
178
182 std::string KindStr() const;
183
184 void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
185 BOARD_ITEM* Parent() const { return m_parent; }
186
190 virtual BOARD_ITEM* BoardItem() const { return m_parent; }
191
192 void SetNet( NET_HANDLE aNet ) { m_net = aNet; }
193 virtual NET_HANDLE Net() const { return m_net; }
194
195 const LAYER_RANGE& Layers() const { return m_layers; }
196 void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
197
198 void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
199 virtual int Layer() const { return Layers().Start(); }
200
204 bool LayersOverlap( const ITEM* aOther ) const
205 {
206 return Layers().Overlaps( aOther->Layers() );
207 }
208
218 bool Collide( const ITEM* aHead, const NODE* aNode,
219 COLLISION_SEARCH_CONTEXT* aCtx = nullptr ) const;
220
224 virtual const SHAPE* Shape() const
225 {
226 return nullptr;
227 }
228
229 virtual void Mark( int aMarker ) const { m_marker = aMarker; }
230 virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
231 virtual int Marker() const { return m_marker; }
232
233 virtual void SetRank( int aRank ) { m_rank = aRank; }
234 virtual int Rank() const { return m_rank; }
235
236 virtual VECTOR2I Anchor( int n ) const
237 {
238 return VECTOR2I();
239 }
240
241 virtual int AnchorCount() const
242 {
243 return 0;
244 }
245
246 bool IsLocked() const
247 {
248 return Marker() & MK_LOCKED;
249 }
250
251 void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
252 bool IsRoutable() const { return m_routable; }
253
254 void SetIsFreePad( bool aIsFreePad = true ) { m_isFreePad = aIsFreePad; }
255
256 bool IsFreePad() const
257 {
258 return m_isFreePad || ( ParentPadVia() && ParentPadVia()->m_isFreePad );
259 }
260
261 virtual ITEM* ParentPadVia() const { return nullptr; }
262
263 bool IsVirtual() const
264 {
265 return m_isVirtual;
266 }
267
270
271 virtual bool HasHole() const { return false; }
272 virtual HOLE *Hole() const { return nullptr; }
273 virtual void SetHole( HOLE* aHole ) {};
274
275 virtual const std::string Format() const;
276
277 virtual const NODE* OwningNode() const;
278
279private:
280 bool collideSimple( const ITEM* aHead, const NODE* aNode,
281 COLLISION_SEARCH_CONTEXT* aCtx ) const;
282
283protected:
285
288
291 mutable int m_marker;
297};
298
299template<typename T, typename S>
300std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
301{
302 static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
303 static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
304 return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
305}
306
307template<typename T>
308std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
309{
310 static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
311 return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
312}
313
314}
315
316#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:185
bool IsFreePad() const
Definition: pns_item.h:256
PnsKind m_kind
Definition: pns_item.h:284
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:196
void SetIsFreePad(bool aIsFreePad=true)
Definition: pns_item.h:254
virtual const std::string Format() const
Definition: pns_item.cpp:301
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:230
virtual int Rank() const
Definition: pns_item.h:234
bool m_isVirtual
Definition: pns_item.h:294
virtual ITEM * ParentPadVia() const
Definition: pns_item.h:261
bool m_movable
Definition: pns_item.h:289
ITEM(const ITEM &aOther)
Definition: pns_item.h:128
ITEM(PnsKind aKind)
Definition: pns_item.h:113
virtual NET_HANDLE Net() const
Definition: pns_item.h:193
virtual void SetHole(HOLE *aHole)
Definition: pns_item.h:273
bool m_routable
Definition: pns_item.h:293
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:166
virtual ITEM * Clone() const =0
Return a deep copy of the item.
void SetNet(NET_HANDLE aNet)
Definition: pns_item.h:192
virtual void SetRank(int aRank)
Definition: pns_item.h:233
LAYER_RANGE m_layers
Definition: pns_item.h:287
NET_HANDLE m_net
Definition: pns_item.h:290
virtual int Layer() const
Definition: pns_item.h:199
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:224
void SetLayer(int aLayer)
Definition: pns_item.h:198
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:268
PnsKind
< Supported item types
Definition: pns_item.h:101
@ SEGMENT_T
Definition: pns_item.h:105
@ DIFF_PAIR_T
Definition: pns_item.h:108
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:184
const LAYER_RANGE & Layers() const
Definition: pns_item.h:195
bool m_isFreePad
Definition: pns_item.h:295
virtual ~ITEM()
Definition: pns_item.cpp:296
virtual const NODE * OwningNode() const
Definition: pns_item.cpp:317
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:269
int m_marker
Definition: pns_item.h:291
bool OfKind(int aKindMask) const
Definition: pns_item.h:174
bool IsVirtual() const
Definition: pns_item.h:263
bool IsRoutable() const
Definition: pns_item.h:252
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:236
std::string KindStr() const
Definition: pns_item.cpp:278
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:204
bool m_isCompoundShapePrimitive
Definition: pns_item.h:296
virtual HOLE * Hole() const
Definition: pns_item.h:272
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:269
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:157
virtual void Mark(int aMarker) const
Definition: pns_item.h:229
virtual int AnchorCount() const
Definition: pns_item.h:241
virtual bool HasHole() const
Definition: pns_item.h:271
virtual BOARD_ITEM * BoardItem() const
Definition: pns_item.h:190
void SetRoutable(bool aRoutable)
Definition: pns_item.h:251
bool IsLocked() const
Definition: pns_item.h:246
virtual int Marker() const
Definition: pns_item.h:231
BOARD_ITEM * m_parent
Definition: pns_item.h:286
int m_rank
Definition: pns_item.h:292
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:300
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:308
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588