KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_item.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wandadoo.fr
5 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef BOARD_ITEM_STRUCT_H
26#define BOARD_ITEM_STRUCT_H
27
28
29#include <eda_item.h>
30#include <layer_ids.h>
31#include <lseq.h>
32#include <lset.h>
34#include <stroke_params.h>
35#include <geometry/eda_angle.h>
36
37class BOARD;
40class SHAPE_POLY_SET;
41class SHAPE_SEGMENT;
42class PCB_BASE_FRAME;
43class SHAPE;
44class PCB_GROUP;
45class FOOTPRINT;
46
47namespace KIFONT
48{
49class METRICS;
50}
51
52
66{
70};
71
72
78class BOARD_ITEM : public EDA_ITEM
79{
80public:
81 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
82 EDA_ITEM( aParent, idtype ),
83 m_layer( aLayer ),
84 m_isKnockout( false ),
85 m_isLocked( false ),
86 m_group( nullptr )
87 {
88 }
89
91
92 void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
93 PCB_GROUP* GetParentGroup() const { return m_group; }
94
95 // Do not create a copy constructor & operator=.
96 // The ones generated by the compiler are adequate.
97 int GetX() const
98 {
100 return p.x;
101 }
102
103 int GetY() const
104 {
105 VECTOR2I p = GetPosition();
106 return p.y;
107 }
108
114 virtual VECTOR2I GetCenter() const
115 {
116 return GetBoundingBox().GetCenter();
117 }
118
119 void SetX( int aX )
120 {
121 VECTOR2I p( aX, GetY() );
122 SetPosition( p );
123 }
124
125 void SetY( int aY )
126 {
127 VECTOR2I p( GetX(), aY );
128 SetPosition( p );
129 }
130
136 virtual bool IsConnected() const
137 {
138 return false;
139 }
140
147 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
148 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
149
153 virtual bool IsOnCopperLayer() const
154 {
155 return IsCopperLayer( GetLayer() );
156 }
157
158 virtual bool HasHole() const
159 {
160 return false;
161 }
162
163 virtual bool HasDrilledHole() const
164 {
165 return false;
166 }
167
175 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
176 {
177 return false;
178 }
179
184
200 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
201 FLASHING aFlash = FLASHING::DEFAULT ) const;
202
203 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
204
209 virtual void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const { }
210
215 virtual void RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFunction,
216 int aDepth = 0 ) const { }
217
219
221
223 void SetFPRelativePosition( const VECTOR2I& aPos );
224
230 virtual bool HasLineStroke() const { return false; }
231
232 virtual STROKE_PARAMS GetStroke() const;
233 virtual void SetStroke( const STROKE_PARAMS& aStroke );
234
235 const KIFONT::METRICS& GetFontMetrics() const;
236
240 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
241
245 virtual LSET GetLayerSet() const
246 {
247 if( m_layer == UNDEFINED_LAYER )
248 return LSET();
249 else
250 return LSET( m_layer );
251 }
252
253 virtual void SetLayerSet( LSET aLayers )
254 {
255 if( aLayers.count() == 1 )
256 {
257 SetLayer( aLayers.Seq()[0] );
258 return;
259 }
260
261 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
262
263 // Derived classes which support multiple layers must implement this
264 }
265
266 bool IsSideSpecific() const;
267
276 virtual void SetLayer( PCB_LAYER_ID aLayer )
277 {
278 m_layer = aLayer;
279 }
280
284 virtual BOARD_ITEM* Duplicate() const;
285
296 void SwapItemData( BOARD_ITEM* aImage );
297
307 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
308 {
309 return m_layer == aLayer;
310 }
311
312 virtual bool IsKnockout() const { return m_isKnockout; }
313 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
314
315 virtual bool IsLocked() const;
316 virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; }
317
318 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) { }
319
323 void DeleteStructure();
324
330 virtual void Move( const VECTOR2I& aMoveVector )
331 {
332 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
333 }
334
340 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
341
348 virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
349
353 virtual void Normalize() {}
354
358 virtual const BOARD* GetBoard() const;
359 virtual BOARD* GetBoard();
360
365 wxString GetParentAsString() const;
366
372 wxString GetLayerName() const;
373
374 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
375
386 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
387 int aClearance, int aError, ERROR_LOC aErrorLoc,
388 bool ignoreLineWidth = false ) const;
389
390 enum COMPARE_FLAGS : int
391 {
392 DRC = 0x01
393 };
394
395 struct ptr_cmp
396 {
397 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
398 };
399
400protected:
404 virtual wxString layerMaskDescribe() const;
405
406 virtual void swapData( BOARD_ITEM* aImage );
407
408protected:
411
413
415};
416
417#ifndef SWIG
419#endif
420
421
428{
429public:
431 BOARD_ITEM( nullptr, NOT_USED )
432 {}
433
434 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
435 {
436 return _( "(Deleted Item)" );
437 }
438
439 wxString GetClass() const override
440 {
441 return wxT( "DELETED_BOARD_ITEM" );
442 }
443
444 // pure virtuals:
445 void SetPosition( const VECTOR2I& ) override {}
446 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
447
449 {
450 static DELETED_BOARD_ITEM* item = nullptr;
451
452 if( !item )
453 item = new DELETED_BOARD_ITEM();
454
455 return item;
456 }
457
458 double Similarity( const BOARD_ITEM& aItem ) const override
459 {
460 return ( this == &aItem ) ? 1.0 : 0.0;
461 }
462
463 bool operator==( const BOARD_ITEM& aBoardItem ) const override
464 {
465 return ( this == &aBoardItem );
466 }
467
468 bool operator==( const DELETED_BOARD_ITEM& aOther ) const
469 {
470 return ( this == &aOther );
471 }
472
473#if defined(DEBUG)
474 void Show( int , std::ostream& ) const override {}
475#endif
476};
477
478
479#endif /* BOARD_ITEM_STRUCT_H */
ZONE_LAYER_OVERRIDE
Conditionally flashed vias and pads that interact with zones of different priority can be very squirr...
Definition: board_item.h:66
@ ZLO_NONE
Definition: board_item.h:67
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition: board_item.h:69
@ ZLO_FORCE_FLASHED
Definition: board_item.h:68
size_t count() const
Definition: base_set.h:106
Container for design settings for a BOARD object.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition: board_item.h:81
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:240
virtual void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings)
Definition: board_item.h:318
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:92
int GetY() const
Definition: board_item.h:103
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:175
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:191
virtual void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:327
virtual STROKE_PARAMS GetStroke() const
Definition: board_item.cpp:86
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:136
bool m_isKnockout
Definition: board_item.h:410
virtual void SetLocked(bool aLocked)
Definition: board_item.h:316
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:93
PCB_GROUP * m_group
Definition: board_item.h:414
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: board_item.cpp:92
PCB_LAYER_ID m_layer
Definition: board_item.h:409
bool m_isLocked
Definition: board_item.h:412
wxString GetParentAsString() const
For "parent" property.
Definition: board_item.cpp:333
virtual bool IsKnockout() const
Definition: board_item.h:312
int GetX() const
Definition: board_item.h:97
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
Definition: board_item.cpp:221
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
Definition: board_item.cpp:321
void SetX(int aX)
Definition: board_item.h:119
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:209
void SetY(int aY)
Definition: board_item.h:125
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:114
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:330
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:307
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:313
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:276
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:244
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:264
VECTOR2I GetFPRelativePosition() const
Definition: board_item.cpp:293
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:245
virtual bool IsTented(PCB_LAYER_ID aLayer) const
Checks if the given object is tented (its copper shape is covered by solder mask) on a given side of ...
Definition: board_item.h:175
virtual void swapData(BOARD_ITEM *aImage)
Definition: board_item.cpp:186
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:98
void SetFPRelativePosition(const VECTOR2I &aPos)
Definition: board_item.cpp:307
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:183
virtual bool IsLocked() const
Definition: board_item.cpp:75
virtual bool operator==(const BOARD_ITEM &aItem) const =0
virtual bool HasDrilledHole() const
Definition: board_item.h:163
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:218
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: board_item.cpp:164
bool IsSideSpecific() const
Definition: board_item.cpp:114
virtual bool IsOnCopperLayer() const
Definition: board_item.h:153
virtual void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction, int aDepth=0) const
Invoke a function on all descendants.
Definition: board_item.h:215
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition: board_item.h:230
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition: board_item.h:353
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:131
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:104
virtual double Similarity(const BOARD_ITEM &aItem) const =0
Return a measure of how likely the other object is to represent the same object.
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:254
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:253
virtual bool HasHole() const
Definition: board_item.h:158
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all children.
Definition: board_item.h:209
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
const Vec GetCenter() const
Definition: box2.h:220
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: board_item.h:428
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: board_item.h:434
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:448
wxString GetClass() const override
Return the class name.
Definition: board_item.h:439
double Similarity(const BOARD_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: board_item.h:458
VECTOR2I GetPosition() const override
Definition: board_item.h:446
void SetPosition(const VECTOR2I &) override
Definition: board_item.h:445
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition: board_item.h:463
bool operator==(const DELETED_BOARD_ITEM &aOther) const
Definition: board_item.h:468
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:244
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
virtual wxString GetClass() const =0
Return the class name.
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:500
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:392
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
Represent a set of closed polygons.
An abstract shape on 2D plane.
Definition: shape.h:126
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
#define _(s)
a few functions useful in geometry calculations.
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:149
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:531
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:729
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:229
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:673