KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 The 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#pragma once
26
27
28#include <core/mirror.h>
29#include <eda_item.h>
31#include <layer_ids.h>
32#include <lseq.h>
33#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
77class BOARD_ITEM : public EDA_ITEM
78{
79public:
80 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
81 EDA_ITEM( aParent, idtype, false, true ),
82 m_layer( aLayer ),
83 m_isKnockout( false ),
84 m_isLocked( false ),
85 m_group( nullptr )
86 {
87 }
88
90
91 virtual void CopyFrom( const BOARD_ITEM* aOther );
92
93 void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
94 PCB_GROUP* GetParentGroup() const { return m_group; }
95
96 // Do not create a copy constructor & operator=.
97 // The ones generated by the compiler are adequate.
98 int GetX() const
99 {
100 VECTOR2I p = GetPosition();
101 return p.x;
102 }
103
104 int GetY() const
105 {
106 VECTOR2I p = GetPosition();
107 return p.y;
108 }
109
115 virtual VECTOR2I GetCenter() const
116 {
117 return GetBoundingBox().GetCenter();
118 }
119
120 void SetX( int aX )
121 {
122 VECTOR2I p( aX, GetY() );
123 SetPosition( p );
124 }
125
126 void SetY( int aY )
127 {
128 VECTOR2I p( GetX(), aY );
129 SetPosition( p );
130 }
131
137 virtual bool IsConnected() const
138 {
139 return false;
140 }
141
148 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
149 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
150
154 virtual bool IsOnCopperLayer() const
155 {
156 return IsCopperLayer( GetLayer() );
157 }
158
159 virtual bool HasHole() const
160 {
161 return false;
162 }
163
164 virtual bool HasDrilledHole() const
165 {
166 return false;
167 }
168
176 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
177 {
178 return false;
179 }
180
185
201 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
202 FLASHING aFlash = FLASHING::DEFAULT ) const;
203
204 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
205
211 virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
212
214
216
218 void SetFPRelativePosition( const VECTOR2I& aPos );
219
225 virtual bool HasLineStroke() const { return false; }
226
227 virtual STROKE_PARAMS GetStroke() const;
228 virtual void SetStroke( const STROKE_PARAMS& aStroke );
229
230 const KIFONT::METRICS& GetFontMetrics() const;
231
235 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
236
240 virtual int BoardLayerCount() const;
241
245 virtual int BoardCopperLayerCount() const;
246
250 virtual LSET BoardLayerSet() const;
251
255 virtual LSET GetLayerSet() const
256 {
257 if( m_layer == UNDEFINED_LAYER )
258 return LSET();
259 else
260 return LSET( { m_layer } );
261 }
262
263 virtual void SetLayerSet( const LSET& aLayers )
264 {
265 if( aLayers.count() == 1 )
266 {
267 SetLayer( aLayers.Seq()[0] );
268 return;
269 }
270
271 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
272
273 // Derived classes which support multiple layers must implement this
274 }
275
276 bool IsSideSpecific() const;
277
286 virtual void SetLayer( PCB_LAYER_ID aLayer )
287 {
288 m_layer = aLayer;
289 }
290
294 virtual BOARD_ITEM* Duplicate() const;
295
306 void SwapItemData( BOARD_ITEM* aImage );
307
317 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
318 {
319 return m_layer == aLayer;
320 }
321
322 virtual bool IsKnockout() const { return m_isKnockout; }
323 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
324
325 virtual bool IsLocked() const;
326 virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; }
327
328 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) { }
329
333 void DeleteStructure();
334
340 virtual void Move( const VECTOR2I& aMoveVector )
341 {
342 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
343 }
344
350 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
351
358 virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
359
366 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
367
371 virtual void Normalize() {}
372
378 virtual void NormalizeForCompare() { Normalize(); }
379
383 virtual const BOARD* GetBoard() const;
384 virtual BOARD* GetBoard();
385
390 wxString GetParentAsString() const;
391
397 wxString GetLayerName() const;
398
399 virtual std::vector<int> ViewGetLayers() const override;
400
411 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
412 int aClearance, int aError, ERROR_LOC aErrorLoc,
413 bool ignoreLineWidth = false ) const;
414
427 int aClearance, int aError, ERROR_LOC aErrorLoc ) const
428 {
429 TransformShapeToPolygon( aBuffer, aLayer, aClearance, aError, aErrorLoc );
430 }
431
432 enum COMPARE_FLAGS : int
433 {
434 DRC = 0x01
435 };
436
437 struct ptr_cmp
438 {
439 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
440 };
441
442protected:
446 virtual wxString layerMaskDescribe() const;
447
448 virtual void swapData( BOARD_ITEM* aImage );
449
450protected:
453
455
457};
458
459#ifndef SWIG
461#endif
462
463
470{
471public:
473 BOARD_ITEM( nullptr, NOT_USED )
474 {}
475
476 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
477 {
478 return _( "(Deleted Item)" );
479 }
480
481 wxString GetClass() const override
482 {
483 return wxT( "DELETED_BOARD_ITEM" );
484 }
485
486 // pure virtuals:
487 void SetPosition( const VECTOR2I& ) override {}
488 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
489
491 {
492 static DELETED_BOARD_ITEM* item = nullptr;
493
494 if( !item )
495 item = new DELETED_BOARD_ITEM();
496
497 return item;
498 }
499
500 double Similarity( const BOARD_ITEM& aItem ) const override
501 {
502 return ( this == &aItem ) ? 1.0 : 0.0;
503 }
504
505 bool operator==( const BOARD_ITEM& aBoardItem ) const override
506 {
507 return ( this == &aBoardItem );
508 }
509
510 bool operator==( const DELETED_BOARD_ITEM& aOther ) const
511 {
512 return ( this == &aOther );
513 }
514
515#if defined(DEBUG)
516 void Show( int , std::ostream& ) const override {}
517#endif
518};
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
Definition: approximation.h:32
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
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:78
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition: board_item.h:80
virtual void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Mirror this object relative to a given horizontal axis the layer is not changed.
Definition: board_item.cpp:374
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:235
virtual void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings)
Definition: board_item.h:328
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:93
int GetY() const
Definition: board_item.h:104
virtual void NormalizeForCompare()
Perform any normalization required to compare 2 graphics, especially if the can be rotated and/or fli...
Definition: board_item.h:378
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:216
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:232
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc) const
Convert the item shape to a polyset.
Definition: board_item.h:426
virtual STROKE_PARAMS GetStroke() const
Definition: board_item.cpp:93
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:137
bool m_isKnockout
Definition: board_item.h:452
virtual void SetLocked(bool aLocked)
Definition: board_item.h:326
virtual int BoardLayerCount() const
Return the total number of layers for the board that this item resides on.
Definition: board_item.cpp:113
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:94
PCB_GROUP * m_group
Definition: board_item.h:456
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: board_item.cpp:101
PCB_LAYER_ID m_layer
Definition: board_item.h:451
virtual void SetLayerSet(const LSET &aLayers)
Definition: board_item.h:263
bool m_isLocked
Definition: board_item.h:454
wxString GetParentAsString() const
For "parent" property.
Definition: board_item.cpp:380
virtual bool IsKnockout() const
Definition: board_item.h:322
int GetX() const
Definition: board_item.h:98
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:262
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
Definition: board_item.cpp:362
void SetX(int aX)
Definition: board_item.h:120
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:250
void SetY(int aY)
Definition: board_item.h:126
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:115
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:340
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:317
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:323
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:286
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition: board_item.cpp:206
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:285
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:54
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:305
VECTOR2I GetFPRelativePosition() const
Definition: board_item.cpp:334
virtual LSET BoardLayerSet() const
Return the LSET for the board that this item resides on.
Definition: board_item.cpp:135
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:255
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:176
virtual void swapData(BOARD_ITEM *aImage)
Definition: board_item.cpp:227
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:107
void SetFPRelativePosition(const VECTOR2I &aPos)
Definition: board_item.cpp:348
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:184
virtual bool IsLocked() const
Definition: board_item.cpp:82
virtual void CopyFrom(const BOARD_ITEM *aOther)
Definition: board_item.cpp:47
virtual bool operator==(const BOARD_ITEM &aItem) const =0
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition: board_item.h:211
virtual bool HasDrilledHole() const
Definition: board_item.h:164
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:213
bool IsSideSpecific() const
Definition: board_item.cpp:156
virtual int BoardCopperLayerCount() const
Return the total number of copper layers for the board that this item resides on.
Definition: board_item.cpp:124
virtual bool IsOnCopperLayer() const
Definition: board_item.h:154
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition: board_item.h:225
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition: board_item.h:371
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:173
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:146
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:295
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
Definition: board_item.cpp:368
virtual bool HasHole() const
Definition: board_item.h:159
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
constexpr const Vec GetCenter() const
Definition: box2.h:230
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: board_item.h:470
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: board_item.h:476
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:490
wxString GetClass() const override
Return the class name.
Definition: board_item.h:481
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:500
VECTOR2I GetPosition() const override
Definition: board_item.h:488
void SetPosition(const VECTOR2I &) override
Definition: board_item.h:487
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition: board_item.h:505
bool operator==(const DELETED_BOARD_ITEM &aOther) const
Definition: board_item.h:510
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:95
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:248
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:249
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:81
virtual wxString GetClass() const =0
Return the class name.
EDA_ITEM * m_parent
Linked list: Link (parent struct).
Definition: eda_item.h:506
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:37
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:297
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:94
#define _(s)
RECURSE_MODE
Definition: eda_item.h:49
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:184
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition: layer_ids.h:663
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
FLIP_DIRECTION
Definition: mirror.h:27
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:746
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:270
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:695