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
53class ITEM_OWNER {};
54
56{
57public:
59 m_owner( nullptr )
60 {}
61
65 const ITEM_OWNER* Owner() const { return m_owner; }
66
70 void SetOwner( const ITEM_OWNER* aOwner ) { m_owner = aOwner; }
71
75 bool BelongsTo( const ITEM_OWNER* aNode ) const
76 {
77 return m_owner == aNode;
78 }
79
80protected:
82};
83
90class ITEM : public OWNABLE_ITEM, public ITEM_OWNER
91{
92public:
93 static const int UnusedNet = INT_MAX;
94
97 {
99 LINE_T = 2,
102 ARC_T = 16,
103 VIA_T = 32,
105 HOLE_T = 128,
106 ANY_T = 0xffff
107 };
108
109 ITEM( PnsKind aKind )
110 {
112 m_movable = true;
113 m_kind = aKind;
114 m_parent = nullptr;
115 m_owner = nullptr;
116 m_marker = 0;
117 m_rank = -1;
118 m_routable = true;
119 m_isVirtual = false;
120 m_isFreePad = false;
122 }
123
124 ITEM( const ITEM& aOther )
125 {
126 m_layers = aOther.m_layers;
127 m_net = aOther.m_net;
128 m_movable = aOther.m_movable;
129 m_kind = aOther.m_kind;
130 m_parent = aOther.m_parent;
131 m_owner = nullptr;
132 m_marker = aOther.m_marker;
133 m_rank = aOther.m_rank;
134 m_routable = aOther.m_routable;
135 m_isVirtual = aOther.m_isVirtual;
136 m_isFreePad = aOther.m_isFreePad;
138 }
139
140 virtual ~ITEM();
141
145 virtual ITEM* Clone() const = 0;
146
147 /*
148 * Returns a convex polygon "hull" of a the item, that is used as the walk-around path.
149 *
150 * @param aClearance defines how far from the body of the item the hull should be,
151 * @param aWalkaroundThickness is the width of the line that walks around this hull.
152 */
153 virtual const SHAPE_LINE_CHAIN Hull( int aClearance = 0, int aWalkaroundThickness = 0,
154 int aLayer = -1 ) const
155 {
156 return SHAPE_LINE_CHAIN();
157 }
158
162 PnsKind Kind() const
163 {
164 return m_kind;
165 }
166
170 bool OfKind( int aKindMask ) const
171 {
172 return ( aKindMask & m_kind ) != 0;
173 }
174
178 std::string KindStr() const;
179
180 void SetParent( BOARD_ITEM* aParent ) { m_parent = aParent; }
181 BOARD_ITEM* Parent() const { return m_parent; }
182
186 virtual BOARD_ITEM* BoardItem() const { return m_parent; }
187
188 void SetNet( int aNet ) { m_net = aNet; }
189 virtual int Net() const { return m_net; }
190
191 const LAYER_RANGE& Layers() const { return m_layers; }
192 void SetLayers( const LAYER_RANGE& aLayers ) { m_layers = aLayers; }
193
194 void SetLayer( int aLayer ) { m_layers = LAYER_RANGE( aLayer, aLayer ); }
195 virtual int Layer() const { return Layers().Start(); }
196
200 bool LayersOverlap( const ITEM* aOther ) const
201 {
202 return Layers().Overlaps( aOther->Layers() );
203 }
204
214 bool Collide( const ITEM* aHead, const NODE* aNode,
215 COLLISION_SEARCH_CONTEXT* aCtx = nullptr ) const;
216
220 virtual const SHAPE* Shape() const
221 {
222 return nullptr;
223 }
224
225 virtual void Mark( int aMarker ) const { m_marker = aMarker; }
226 virtual void Unmark( int aMarker = -1 ) const { m_marker &= ~aMarker; }
227 virtual int Marker() const { return m_marker; }
228
229 virtual void SetRank( int aRank ) { m_rank = aRank; }
230 virtual int Rank() const { return m_rank; }
231
232 virtual VECTOR2I Anchor( int n ) const
233 {
234 return VECTOR2I();
235 }
236
237 virtual int AnchorCount() const
238 {
239 return 0;
240 }
241
242 bool IsLocked() const
243 {
244 return Marker() & MK_LOCKED;
245 }
246
247 void SetRoutable( bool aRoutable ) { m_routable = aRoutable; }
248 bool IsRoutable() const { return m_routable; }
249
250 void SetIsFreePad( bool aIsFreePad = true ) { m_isFreePad = aIsFreePad; }
251 bool IsFreePad() const { return m_isFreePad; }
252
253 virtual ITEM* ParentPadVia() const { return nullptr; }
254 virtual bool HasSameParentPadVia( const ITEM* aOther ) const
255 {
256 return ParentPadVia() && aOther->ParentPadVia()
257 && ParentPadVia()->Parent() == aOther->ParentPadVia()->Parent();
258 }
259
260 bool IsVirtual() const
261 {
262 return m_isVirtual;
263 }
264
267
268 virtual bool HasHole() const { return false; }
269 virtual HOLE *Hole() const { return nullptr; }
270 virtual void SetHole( HOLE* aHole ) {};
271
272 virtual const std::string Format() const;
273
274private:
275 bool collideSimple( const ITEM* aHead, const NODE* aNode,
276 COLLISION_SEARCH_CONTEXT* aCtx ) const;
277
278protected:
280
283
285 int m_net;
286 mutable int m_marker;
292};
293
294template<typename T, typename S>
295std::unique_ptr<T> ItemCast( std::unique_ptr<S> aPtr )
296{
297 static_assert( std::is_base_of<ITEM, S>::value, "Need to be handed a ITEM!" );
298 static_assert( std::is_base_of<ITEM, T>::value, "Need to cast to an ITEM!" );
299 return std::unique_ptr<T>( static_cast<T*>( aPtr.release() ) );
300}
301
302template<typename T>
303std::unique_ptr< typename std::remove_const<T>::type > Clone( const T& aItem )
304{
305 static_assert( std::is_base_of<ITEM, T>::value, "Need to be handed an ITEM!" );
306 return std::unique_ptr<typename std::remove_const<T>::type>( aItem.Clone() );
307}
308
309}
310
311#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:71
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:91
BOARD_ITEM * Parent() const
Definition: pns_item.h:181
bool IsFreePad() const
Definition: pns_item.h:251
PnsKind m_kind
Definition: pns_item.h:279
void SetLayers(const LAYER_RANGE &aLayers)
Definition: pns_item.h:192
void SetIsFreePad(bool aIsFreePad=true)
Definition: pns_item.h:250
virtual const std::string Format() const
Definition: pns_item.cpp:242
virtual void Unmark(int aMarker=-1) const
Definition: pns_item.h:226
virtual int Rank() const
Definition: pns_item.h:230
int m_net
Definition: pns_item.h:285
bool m_isVirtual
Definition: pns_item.h:289
virtual ITEM * ParentPadVia() const
Definition: pns_item.h:253
bool m_movable
Definition: pns_item.h:284
ITEM(const ITEM &aOther)
Definition: pns_item.h:124
virtual bool HasSameParentPadVia(const ITEM *aOther) const
Definition: pns_item.h:254
ITEM(PnsKind aKind)
Definition: pns_item.h:109
virtual void SetHole(HOLE *aHole)
Definition: pns_item.h:270
void SetNet(int aNet)
Definition: pns_item.h:188
bool m_routable
Definition: pns_item.h:288
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:162
virtual ITEM * Clone() const =0
Return a deep copy of the item.
virtual void SetRank(int aRank)
Definition: pns_item.h:229
LAYER_RANGE m_layers
Definition: pns_item.h:282
virtual int Layer() const
Definition: pns_item.h:195
virtual int Net() const
Definition: pns_item.h:189
bool collideSimple(const ITEM *aHead, const NODE *aNode, COLLISION_SEARCH_CONTEXT *aCtx) const
Definition: pns_item.cpp:48
virtual const SHAPE * Shape() const
Return the geometrical shape of the item.
Definition: pns_item.h:220
void SetLayer(int aLayer)
Definition: pns_item.h:194
void SetIsCompoundShapePrimitive()
Definition: pns_item.h:265
@ SOLID_T
Definition: pns_item.h:98
@ LINE_T
Definition: pns_item.h:99
@ SEGMENT_T
Definition: pns_item.h:101
@ DIFF_PAIR_T
Definition: pns_item.h:104
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:180
const LAYER_RANGE & Layers() const
Definition: pns_item.h:191
bool m_isFreePad
Definition: pns_item.h:290
virtual ~ITEM()
Definition: pns_item.cpp:237
static const int UnusedNet
Supported item types.
Definition: pns_item.h:93
bool IsCompoundShapePrimitive() const
Definition: pns_item.h:266
int m_marker
Definition: pns_item.h:286
bool OfKind(int aKindMask) const
Definition: pns_item.h:170
bool IsVirtual() const
Definition: pns_item.h:260
bool IsRoutable() const
Definition: pns_item.h:248
virtual VECTOR2I Anchor(int n) const
Definition: pns_item.h:232
std::string KindStr() const
Definition: pns_item.cpp:219
bool LayersOverlap(const ITEM *aOther) const
Return true if the set of layers spanned by aOther overlaps our layers.
Definition: pns_item.h:200
bool m_isCompoundShapePrimitive
Definition: pns_item.h:291
virtual HOLE * Hole() const
Definition: pns_item.h:269
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:210
virtual const SHAPE_LINE_CHAIN Hull(int aClearance=0, int aWalkaroundThickness=0, int aLayer=-1) const
Definition: pns_item.h:153
virtual void Mark(int aMarker) const
Definition: pns_item.h:225
virtual int AnchorCount() const
Definition: pns_item.h:237
virtual bool HasHole() const
Definition: pns_item.h:268
virtual BOARD_ITEM * BoardItem() const
Definition: pns_item.h:186
void SetRoutable(bool aRoutable)
Definition: pns_item.h:247
bool IsLocked() const
Definition: pns_item.h:242
virtual int Marker() const
Definition: pns_item.h:227
BOARD_ITEM * m_parent
Definition: pns_item.h:281
int m_rank
Definition: pns_item.h:287
Keep the router "world" - i.e.
Definition: pns_node.h:198
void SetOwner(const ITEM_OWNER *aOwner)
Set the node that owns this item.
Definition: pns_item.h:70
const ITEM_OWNER * m_owner
Definition: pns_item.h:81
bool BelongsTo(const ITEM_OWNER *aNode) const
Definition: pns_item.h:75
const ITEM_OWNER * Owner() const
Return the owner of this item, or NULL if there's none.
Definition: pns_item.h:65
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:124
Push and Shove diff pair dimensions (gap) settings dialog.
std::unique_ptr< T > ItemCast(std::unique_ptr< S > aPtr)
Definition: pns_item.h:295
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:303
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588