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 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 BOARD_COMMIT;
41class SHAPE_POLY_SET;
42class SHAPE_SEGMENT;
43class PCB_BASE_FRAME;
44class SHAPE;
45class PCB_GROUP;
46class FOOTPRINT;
47
48namespace KIFONT
49{
50class METRICS;
51}
52
53
67{
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, false, true ),
83 m_layer( aLayer ),
84 m_isKnockout( false ),
85 m_isLocked( false )
86 {
87 }
88
89 virtual void CopyFrom( const BOARD_ITEM* aOther );
90
91 bool IsGroupableType() const;
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 HasDrilledHole() const
162 {
163 return false;
164 }
165
173 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
174 {
175 return false;
176 }
177
182
198 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
199 FLASHING aFlash = FLASHING::DEFAULT ) const;
200
201 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
202
208 virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
209
211
213
215 void SetFPRelativePosition( const VECTOR2I& aPos );
216
222 virtual bool HasLineStroke() const { return false; }
223
224 virtual STROKE_PARAMS GetStroke() const;
225 virtual void SetStroke( const STROKE_PARAMS& aStroke );
226
227 const KIFONT::METRICS& GetFontMetrics() const;
228
232 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
233
237 virtual int BoardLayerCount() const;
238
242 virtual int BoardCopperLayerCount() const;
243
247 virtual LSET BoardLayerSet() const;
248
252 virtual LSET GetLayerSet() const
253 {
254 if( m_layer == UNDEFINED_LAYER )
255 return LSET();
256 else
257 return LSET( { m_layer } );
258 }
259
260 virtual void SetLayerSet( const LSET& aLayers )
261 {
262 if( aLayers.count() == 1 )
263 {
264 SetLayer( aLayers.Seq()[0] );
265 return;
266 }
267
268 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
269
270 // Derived classes which support multiple layers must implement this
271 }
272
273 bool IsSideSpecific() const;
274
280 virtual void SetLayer( PCB_LAYER_ID aLayer )
281 {
282 m_layer = aLayer;
283 }
284
291 virtual BOARD_ITEM* Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
292
303 void SwapItemData( BOARD_ITEM* aImage );
304
314 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
315 {
316 return m_layer == aLayer;
317 }
318
319 virtual bool IsKnockout() const { return m_isKnockout; }
320 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
321
322 bool IsLocked() const override;
323 void SetLocked( bool aLocked ) override { m_isLocked = aLocked; }
324
325 int GetMaxError() const;
326
327 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) { }
328
332 void DeleteStructure();
333
339 virtual void Move( const VECTOR2I& aMoveVector )
340 {
341 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
342 }
343
349 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
350
357 virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
358
365 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
366
370 virtual void Normalize() {}
371
377 virtual void NormalizeForCompare() { Normalize(); }
378
382 virtual const BOARD* GetBoard() const;
383 virtual BOARD* GetBoard();
384
389 wxString GetParentAsString() const;
390
396 wxString GetLayerName() const;
397
398 virtual std::vector<int> ViewGetLayers() const override;
399
410 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
411 int aClearance, int aError, ERROR_LOC aErrorLoc,
412 bool ignoreLineWidth = false ) const;
413
426 int aClearance, int aError, ERROR_LOC aErrorLoc ) const
427 {
428 TransformShapeToPolygon( aBuffer, aLayer, aClearance, aError, aErrorLoc );
429 }
430
431 const std::vector<wxString>* GetEmbeddedFonts() override;
432
433 enum COMPARE_FLAGS : int
434 {
435 DRC = 0x01,
437 };
438
439 struct ptr_cmp
440 {
441 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
442 };
443
444protected:
448 virtual wxString layerMaskDescribe() const;
449
450 virtual void swapData( BOARD_ITEM* aImage );
451
452protected:
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:67
@ ZLO_NONE
Definition: board_item.h:68
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition: board_item.h:70
@ ZLO_FORCE_FLASHED
Definition: board_item.h:69
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 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:386
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:232
virtual void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings)
Definition: board_item.h:327
int GetY() const
Definition: board_item.h:101
bool IsGroupableType() const
Definition: board_item.cpp:41
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:283
virtual void NormalizeForCompare()
Perform any normalization required to compare 2 graphics, especially if the can be rotated and/or fli...
Definition: board_item.h:377
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:253
const std::vector< wxString > * GetEmbeddedFonts() override
Definition: board_item.cpp:401
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:270
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:425
void SetLocked(bool aLocked) override
Definition: board_item.h:323
virtual STROKE_PARAMS GetStroke() const
Definition: board_item.cpp:118
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:454
virtual int BoardLayerCount() const
Return the total number of layers for the board that this item resides on.
Definition: board_item.cpp:147
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: board_item.cpp:126
PCB_LAYER_ID m_layer
Definition: board_item.h:453
virtual void SetLayerSet(const LSET &aLayers)
Definition: board_item.h:260
bool m_isLocked
Definition: board_item.h:456
wxString GetParentAsString() const
For "parent" property.
Definition: board_item.cpp:392
virtual bool IsKnockout() const
Definition: board_item.h:319
int GetX() const
Definition: board_item.h:95
bool IsLocked() const override
Definition: board_item.cpp:103
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:303
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
Definition: board_item.cpp:374
void SetX(int aX)
Definition: board_item.h:117
void SetY(int aY)
Definition: board_item.h:123
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:339
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:314
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:320
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:280
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition: board_item.cpp:243
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:326
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:79
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:97
VECTOR2I GetFPRelativePosition() const
Definition: board_item.cpp:346
virtual LSET BoardLayerSet() const
Return the LSET for the board that this item resides on.
Definition: board_item.cpp:169
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:252
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:173
virtual void swapData(BOARD_ITEM *aImage)
Definition: board_item.cpp:264
const KIFONT::METRICS & GetFontMetrics() const
Definition: board_item.cpp:132
@ INSTANCE_TO_INSTANCE
Definition: board_item.h:436
void SetFPRelativePosition(const VECTOR2I &aPos)
Definition: board_item.cpp:360
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:181
virtual void CopyFrom(const BOARD_ITEM *aOther)
Definition: board_item.cpp:72
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:208
virtual bool HasDrilledHole() const
Definition: board_item.h:161
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:210
bool IsSideSpecific() const
Definition: board_item.cpp:190
virtual int BoardCopperLayerCount() const
Return the total number of copper layers for the board that this item resides on.
Definition: board_item.cpp:158
virtual bool IsOnCopperLayer() const
Definition: board_item.h:151
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition: board_item.h:222
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition: board_item.h:370
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:207
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:180
int GetMaxError() const
Definition: board_item.cpp:138
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:336
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
Definition: board_item.cpp:380
virtual bool HasHole() const
Definition: board_item.h:156
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
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:98
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:272
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:273
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:110
EDA_ITEM * m_parent
Owner.
Definition: eda_item.h:528
virtual wxString GetClass() const =0
Return the class name.
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:296
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:53
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:50
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:665
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:763
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:311
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