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>
32#include <stroke_params.h>
33#include <geometry/eda_angle.h>
34
35class BOARD;
38class SHAPE_POLY_SET;
39class SHAPE_SEGMENT;
40class PCB_BASE_FRAME;
41class SHAPE;
42class PCB_GROUP;
43class FOOTPRINT;
44
45namespace KIFONT
46{
47class METRICS;
48}
49
50
64{
68};
69
70
76class BOARD_ITEM : public EDA_ITEM
77{
78public:
79 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
80 EDA_ITEM( aParent, idtype ),
81 m_layer( aLayer ),
82 m_isKnockout( false ),
83 m_isLocked( false ),
84 m_group( nullptr )
85 {
86 }
87
89
90 void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
91 PCB_GROUP* GetParentGroup() const { return m_group; }
92
93 // Do not create a copy constructor & operator=.
94 // The ones generated by the compiler are adequate.
95 int GetX() const
96 {
98 return p.x;
99 }
100
101 int GetY() const
102 {
103 VECTOR2I p = GetPosition();
104 return p.y;
105 }
106
112 virtual VECTOR2I GetCenter() const
113 {
114 return GetBoundingBox().GetCenter();
115 }
116
117 void SetX( int aX )
118 {
119 VECTOR2I p( aX, GetY() );
120 SetPosition( p );
121 }
122
123 void SetY( int aY )
124 {
125 VECTOR2I p( GetX(), aY );
126 SetPosition( p );
127 }
128
134 virtual bool IsConnected() const
135 {
136 return false;
137 }
138
145 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
146 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
147
151 virtual bool IsOnCopperLayer() const
152 {
153 return IsCopperLayer( GetLayer() );
154 }
155
156 virtual bool HasHole() const
157 {
158 return false;
159 }
160
161 virtual bool IsTented() const
162 {
163 return false;
164 }
165
170
186 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
187 FLASHING aFlash = FLASHING::DEFAULT ) const;
188
189 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
190
195 virtual void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const { }
196
201 virtual void RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFunction,
202 int aDepth = 0 ) const { }
203
205
207
209 void SetFPRelativePosition( const VECTOR2I& aPos );
210
216 virtual bool HasLineStroke() const { return false; }
217
218 virtual STROKE_PARAMS GetStroke() const;
219 virtual void SetStroke( const STROKE_PARAMS& aStroke );
220
221 const KIFONT::METRICS& GetFontMetrics() const;
222
226 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
227
231 virtual LSET GetLayerSet() const
232 {
233 if( m_layer == UNDEFINED_LAYER )
234 return LSET();
235 else
236 return LSET( m_layer );
237 }
238
239 virtual void SetLayerSet( LSET aLayers )
240 {
241 if( aLayers.count() == 1 )
242 {
243 SetLayer( aLayers.Seq()[0] );
244 return;
245 }
246
247 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
248
249 // Derived classes which support multiple layers must implement this
250 }
251
260 virtual void SetLayer( PCB_LAYER_ID aLayer )
261 {
262 m_layer = aLayer;
263 }
264
268 virtual BOARD_ITEM* Duplicate() const;
269
280 void SwapItemData( BOARD_ITEM* aImage );
281
291 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
292 {
293 return m_layer == aLayer;
294 }
295
296 virtual bool IsKnockout() const { return m_isKnockout; }
297 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
298
299 virtual bool IsLocked() const;
300 virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; }
301
302 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) { }
303
307 void DeleteStructure();
308
314 virtual void Move( const VECTOR2I& aMoveVector )
315 {
316 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
317 }
318
324 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
325
332 virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
333
337 virtual void Normalize() {}
338
342 virtual const BOARD* GetBoard() const;
343 virtual BOARD* GetBoard();
344
349 wxString GetParentAsString() const;
350
356 wxString GetLayerName() const;
357
358 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
359
370 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
371 int aClearance, int aError, ERROR_LOC aErrorLoc,
372 bool ignoreLineWidth = false ) const;
373
374 struct ptr_cmp
375 {
376 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
377 };
378
379protected:
383 virtual wxString layerMaskDescribe() const;
384
385 virtual void swapData( BOARD_ITEM* aImage );
386
387protected:
390
392
394};
395
396#ifndef SWIG
398#endif
399
400
407{
408public:
410 BOARD_ITEM( nullptr, NOT_USED )
411 {}
412
413 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
414 {
415 return _( "(Deleted Item)" );
416 }
417
418 wxString GetClass() const override
419 {
420 return wxT( "DELETED_BOARD_ITEM" );
421 }
422
423 // pure virtuals:
424 void SetPosition( const VECTOR2I& ) override {}
425 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
426
428 {
429 static DELETED_BOARD_ITEM* item = nullptr;
430
431 if( !item )
432 item = new DELETED_BOARD_ITEM();
433
434 return item;
435 }
436
437 double Similarity( const BOARD_ITEM& aItem ) const override
438 {
439 return ( this == &aItem ) ? 1.0 : 0.0;
440 }
441
442 bool operator==( const BOARD_ITEM& aItem ) const override
443 {
444 return ( this == &aItem );
445 }
446
447#if defined(DEBUG)
448 void Show( int , std::ostream& ) const override {}
449#endif
450};
451
452
453#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:64
@ ZLO_NONE
Definition: board_item.h:65
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition: board_item.h:67
@ ZLO_FORCE_FLASHED
Definition: board_item.h:66
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:77
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings)
Definition: board_item.h:302
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:90
int GetY() const
Definition: board_item.h:101
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:159
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:175
virtual void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:296
virtual STROKE_PARAMS GetStroke() const
Definition: board_item.cpp:85
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:134
bool m_isKnockout
Definition: board_item.h:389
virtual void SetLocked(bool aLocked)
Definition: board_item.h:300
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:91
PCB_GROUP * m_group
Definition: board_item.h:393
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: board_item.cpp:91
PCB_LAYER_ID m_layer
Definition: board_item.h:388
bool m_isLocked
Definition: board_item.h:391
wxString GetParentAsString() const
For "parent" property.
Definition: board_item.cpp:302
virtual bool IsKnockout() const
Definition: board_item.h:296
int GetX() const
Definition: board_item.h:95
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:205
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
Definition: board_item.cpp:290
void SetX(int aX)
Definition: board_item.h:117
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:193
void SetY(int aY)
Definition: board_item.h:123
virtual bool IsTented() const
Definition: board_item.h:161
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:112
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:314
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:291
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:297
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
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:228
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:248
VECTOR2I GetFPRelativePosition() const
Definition: board_item.cpp:262
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:231
virtual void swapData(BOARD_ITEM *aImage)
Definition: board_item.cpp:170
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:97
void SetFPRelativePosition(const VECTOR2I &aPos)
Definition: board_item.cpp:276
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:169
virtual bool IsLocked() const
Definition: board_item.cpp:74
virtual bool operator==(const BOARD_ITEM &aItem) const =0
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:204
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:148
virtual bool IsOnCopperLayer() const
Definition: board_item.h:151
virtual void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction, int aDepth=0) const
Invoke a function on all descendants.
Definition: board_item.h:201
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition: board_item.h:216
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition: board_item.h:337
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:115
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:103
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:238
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:239
virtual bool HasHole() const
Definition: board_item.h:156
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all children.
Definition: board_item.h:195
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
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:407
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:427
wxString GetClass() const override
Return the class name.
Definition: board_item.h:418
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: board_item.h:413
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:437
VECTOR2I GetPosition() const override
Definition: board_item.h:425
void SetPosition(const VECTOR2I &) override
Definition: board_item.h:424
bool operator==(const BOARD_ITEM &aItem) const override
Definition: board_item.h:442
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:242
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:243
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:488
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
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:418
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:51
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:881
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:213
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< int > VECTOR2I
Definition: vector2d.h:588