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, see <https://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
23
24#include <core/mirror.h>
25#include <eda_item.h>
27#include <layer_ids.h>
28#include <properties/property.h>
29#include <lseq.h>
30#include <lset.h>
31#include <stroke_params.h>
32#include <geometry/eda_angle.h>
33#include "macros.h"
34
35class BOARD;
38class BOARD_COMMIT;
39class SHAPE_POLY_SET;
40class SHAPE_SEGMENT;
41class PCB_BASE_FRAME;
42class SHAPE;
43class PCB_GROUP;
44class FOOTPRINT;
45namespace KIGFX
46{
47 class RENDER_SETTINGS;
48};
49
50namespace KIFONT
51{
52class METRICS;
53}
54
55
74
80class BOARD_ITEM : public EDA_ITEM
81{
82public:
83 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
84 EDA_ITEM( aParent, idtype, false, true ),
85 m_layer( aLayer ),
86 m_isKnockout( false ),
87 m_isLocked( false )
88 {
89 }
90
91 BOARD_ITEM( const BOARD_ITEM& aOther ) :
92 EDA_ITEM( aOther ),
93 m_layer( aOther.m_layer ),
94 m_isKnockout( aOther.m_isKnockout ),
95 m_isLocked( aOther.m_isLocked )
96 {
97 // Cache membership is owned by BOARD: clones start detached from any board index
98 }
99
101 {
102 if( this == &aOther )
103 return *this;
104
105 EDA_ITEM::operator=( aOther );
106 m_layer = aOther.m_layer;
107 m_isKnockout = aOther.m_isKnockout;
108 m_isLocked = aOther.m_isLocked;
109 return *this;
110 }
111
112 virtual void CopyFrom( const BOARD_ITEM* aOther );
113
114 bool IsGroupableType() const;
115
116 int GetX() const
117 {
118 VECTOR2I p = GetPosition();
119 return p.x;
120 }
121
122 int GetY() const
123 {
124 VECTOR2I p = GetPosition();
125 return p.y;
126 }
127
133 virtual VECTOR2I GetCenter() const
134 {
135 return GetBoundingBox().GetCenter();
136 }
137
138 void SetX( int aX )
139 {
140 VECTOR2I p( aX, GetY() );
141 SetPosition( p );
142 }
143
144 void SetY( int aY )
145 {
146 VECTOR2I p( GetX(), aY );
147 SetPosition( p );
148 }
149
155 virtual bool IsConnected() const
156 {
157 return false;
158 }
159
166 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
167 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
168
172 virtual bool IsOnCopperLayer() const
173 {
174 return IsCopperLayer( GetLayer() );
175 }
176
177 virtual bool HasHole() const
178 {
179 return false;
180 }
181
182 virtual bool HasDrilledHole() const
183 {
184 return false;
185 }
186
194 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
195 {
196 return false;
197 }
198
203
219 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
220 FLASHING aFlash = FLASHING::DEFAULT ) const;
221
222 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
223
229 virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
230
232
234
240 void SetUuidDirect( const KIID& aUuid );
241
243
244 void SetUuid( const KIID& aUuid );
245 void ResetUuid() { SetUuid( KIID() ); }
246
248 void SetFPRelativePosition( const VECTOR2I& aPos );
249
255 virtual bool HasLineStroke() const { return false; }
256
257 virtual STROKE_PARAMS GetStroke() const;
258 virtual void SetStroke( const STROKE_PARAMS& aStroke );
259
260 const KIFONT::METRICS& GetFontMetrics() const;
261
265 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
266
270 virtual int BoardLayerCount() const;
271
275 virtual int BoardCopperLayerCount() const;
276
280 virtual LSET BoardLayerSet() const;
281
285 virtual LSET GetLayerSet() const
286 {
287 if( m_layer == UNDEFINED_LAYER )
288 return LSET();
289 else
290 return LSET( { m_layer } );
291 }
292
293 virtual void SetLayerSet( const LSET& aLayers )
294 {
295 if( aLayers.count() == 1 )
296 {
297 SetLayer( aLayers.Seq()[0] );
298 return;
299 }
300
302
303 // Derived classes which support multiple layers must implement this
304 }
305
306 bool IsSideSpecific() const;
307
313 virtual void SetLayer( PCB_LAYER_ID aLayer )
314 {
315 m_layer = aLayer;
316 }
317
324 virtual BOARD_ITEM* Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
325
336 void SwapItemData( BOARD_ITEM* aImage );
337
347 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
348 {
349 return m_layer == aLayer;
350 }
351
352 virtual bool IsKnockout() const { return m_isKnockout; }
353 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
354
355 bool IsLocked() const override;
356 void SetLocked( bool aLocked ) override { m_isLocked = aLocked; }
357
358 int GetMaxError() const;
359
360 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide ) { }
361
365 void DeleteStructure();
366
372 virtual void Move( const VECTOR2I& aMoveVector )
373 {
374 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
375 }
376
382 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
383
395 virtual void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
396 const EDA_ANGLE& aParentRotate )
397 {}
398
403 virtual void OnFootprintTransformed() {}
404
411 virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
412
419 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
420
424 virtual void Normalize() {}
425
431 virtual void NormalizeForCompare() { Normalize(); }
432
436 virtual const BOARD* GetBoard() const;
437 virtual BOARD* GetBoard();
438
443 wxString GetParentAsString() const;
444
450 wxString GetLayerName() const;
451
452 virtual std::vector<int> ViewGetLayers() const override;
453
464 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
465 int aClearance, int aError, ERROR_LOC aErrorLoc,
466 bool ignoreLineWidth = false ) const;
467
480 int aClearance, int aError, ERROR_LOC aErrorLoc,
481 KIGFX::RENDER_SETTINGS* aRenderSettings = nullptr ) const
482 {
483 TransformShapeToPolygon( aBuffer, aLayer, aClearance, aError, aErrorLoc );
484 }
485
486 const std::vector<wxString>* GetEmbeddedFonts() override;
487
491 virtual wxString LayerMaskDescribe() const;
492
493 enum COMPARE_FLAGS : int
494 {
495 DRC = 0x01,
497 };
498
499 struct ptr_cmp
500 {
501 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
502 };
503
504protected:
505 virtual void swapData( BOARD_ITEM* aImage );
506
507protected:
511
512 friend class BOARD;
513};
514
516
523{
524public:
526 BOARD_ITEM( nullptr, NOT_USED )
527 {}
528
529 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
530 {
531 return _( "(Deleted Item)" );
532 }
533
534 wxString GetClass() const override
535 {
536 return wxT( "DELETED_BOARD_ITEM" );
537 }
538
539 // pure virtuals:
540 void SetPosition( const VECTOR2I& ) override {}
541 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
542
544 {
545 static DELETED_BOARD_ITEM* item = nullptr;
546
547 if( !item )
548 item = new DELETED_BOARD_ITEM();
549
550 return item;
551 }
552
553 double Similarity( const BOARD_ITEM& aItem ) const override
554 {
555 return ( this == &aItem ) ? 1.0 : 0.0;
556 }
557
558 bool operator==( const BOARD_ITEM& aBoardItem ) const override
559 {
560 return ( this == &aBoardItem );
561 }
562
563 bool operator==( const DELETED_BOARD_ITEM& aOther ) const
564 {
565 return ( this == &aOther );
566 }
567
568#if defined(DEBUG)
569 void Show( int , std::ostream& ) const override {}
570#endif
571};
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
ZONE_LAYER_OVERRIDE
Conditionally flashed vias and pads that interact with zones of different priority can be very squirr...
Definition board_item.h:69
@ ZLO_NONE
Definition board_item.h:70
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition board_item.h:72
@ ZLO_FORCE_FLASHED
Definition board_item.h:71
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:81
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:83
virtual void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Mirror this object relative to a given horizontal axis the layer is not changed.
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:265
friend class BOARD
Definition board_item.h:512
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void ResetUuidDirect()
Definition board_item.h:242
int GetY() const
Definition board_item.h:122
bool IsGroupableType() const
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
virtual void NormalizeForCompare()
Perform any normalization required to compare 2 graphics, especially if the can be rotated and/or fli...
Definition board_item.h:431
virtual void OnFootprintTransformed()
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
Definition board_item.h:403
void DeleteStructure()
Delete this object after removing from its parent if it has one.
const std::vector< wxString > * GetEmbeddedFonts() override
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
void SetLocked(bool aLocked) override
Definition board_item.h:356
virtual STROKE_PARAMS GetStroke() const
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:155
bool m_isKnockout
Definition board_item.h:509
virtual int BoardLayerCount() const
Return the total number of layers for the board that this item resides on.
virtual void SetStroke(const STROKE_PARAMS &aStroke)
void SetUuid(const KIID &aUuid)
PCB_LAYER_ID m_layer
Definition board_item.h:508
BOARD_ITEM(const BOARD_ITEM &aOther)
Definition board_item.h:91
virtual void SetLayerSet(const LSET &aLayers)
Definition board_item.h:293
bool m_isLocked
Definition board_item.h:510
wxString GetParentAsString() const
For "parent" property.
virtual bool IsKnockout() const
Definition board_item.h:352
int GetX() const
Definition board_item.h:116
bool IsLocked() const override
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.
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
void SetX(int aX)
Definition board_item.h:138
void SetY(int aY)
Definition board_item.h:144
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition board_item.h:133
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:372
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:347
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:353
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:313
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
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.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
VECTOR2I GetFPRelativePosition() const
virtual LSET BoardLayerSet() const
Return the LSET for the board that this item resides on.
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:285
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:194
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const
Convert the item shape to a polyset.
Definition board_item.h:479
virtual void swapData(BOARD_ITEM *aImage)
const KIFONT::METRICS & GetFontMetrics() const
@ INSTANCE_TO_INSTANCE
Definition board_item.h:496
void SetFPRelativePosition(const VECTOR2I &aPos)
virtual wxString LayerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition board_item.h:202
virtual void CopyFrom(const BOARD_ITEM *aOther)
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:229
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
Definition board_item.h:100
void ResetUuid()
Definition board_item.h:245
virtual bool HasDrilledHole() const
Definition board_item.h:182
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:231
bool IsSideSpecific() const
virtual int BoardCopperLayerCount() const
Return the total number of copper layers for the board that this item resides on.
virtual bool IsOnCopperLayer() const
Definition board_item.h:172
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition board_item.h:255
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition board_item.h:424
virtual void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate)
Apply a parent footprint scale to this item.
Definition board_item.h:395
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
int GetMaxError() const
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
virtual void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide)
Definition board_item.h:360
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
virtual bool HasHole() const
Definition board_item.h:177
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
constexpr const Vec GetCenter() const
Definition box2.h:226
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition board_item.h:529
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:543
wxString GetClass() const override
Return the class name.
Definition board_item.h:534
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:553
VECTOR2I GetPosition() const override
Definition board_item.h:541
void SetPosition(const VECTOR2I &) override
Definition board_item.h:540
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition board_item.h:558
bool operator==(const DELETED_BOARD_ITEM &aOther) const
Definition board_item.h:563
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition eda_item.cpp:353
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:283
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:135
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:543
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
virtual wxString GetClass() const =0
Return the class name.
Definition kiid.h:44
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:309
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:49
Represent a set of closed polygons.
An abstract shape on 2D plane.
Definition shape.h:124
Simple container to manage line stroke parameters.
#define _(s)
RECURSE_MODE
Definition eda_item.h:48
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:181
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:675
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:92
FLIP_DIRECTION
Definition mirror.h:23
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
#define DECLARE_ENUM_TO_WXANY(type)
Definition property.h:789
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:72
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683