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 <map>
25
26#include <core/mirror.h>
27#include <eda_item.h>
29#include <layer_ids.h>
30#include <properties/property.h>
31#include <lseq.h>
32#include <lset.h>
33#include <stroke_params.h>
34#include <geometry/eda_angle.h>
35#include "macros.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;
47namespace KIGFX
48{
49 class RENDER_SETTINGS;
50};
51
52namespace KIFONT
53{
54class METRICS;
55}
56
57
76
82class BOARD_ITEM : public EDA_ITEM
83{
84public:
85 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
86 EDA_ITEM( aParent, idtype, false, true ),
87 m_layer( aLayer ),
88 m_isKnockout( false ),
89 m_isLocked( false )
90 {
91 }
92
93 BOARD_ITEM( const BOARD_ITEM& aOther ) :
94 EDA_ITEM( aOther ),
95 m_layer( aOther.m_layer ),
96 m_isKnockout( aOther.m_isKnockout ),
97 m_isLocked( aOther.m_isLocked )
98 {
99 // Cache membership is owned by BOARD: clones start detached from any board index
100 }
101
103 {
104 if( this == &aOther )
105 return *this;
106
107 EDA_ITEM::operator=( aOther );
108 m_layer = aOther.m_layer;
109 m_isKnockout = aOther.m_isKnockout;
110 m_isLocked = aOther.m_isLocked;
111 return *this;
112 }
113
114 ~BOARD_ITEM() override;
115
116 virtual void CopyFrom( const BOARD_ITEM* aOther );
117
118 bool IsGroupableType() const;
119
120 int GetX() const
121 {
122 VECTOR2I p = GetPosition();
123 return p.x;
124 }
125
126 int GetY() const
127 {
128 VECTOR2I p = GetPosition();
129 return p.y;
130 }
131
137 virtual VECTOR2I GetCenter() const
138 {
139 return GetBoundingBox().GetCenter();
140 }
141
142 void SetX( int aX )
143 {
144 VECTOR2I p( aX, GetY() );
145 SetPosition( p );
146 }
147
148 void SetY( int aY )
149 {
150 VECTOR2I p( GetX(), aY );
151 SetPosition( p );
152 }
153
159 virtual bool IsConnected() const
160 {
161 return false;
162 }
163
170 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
171 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
172
176 virtual bool IsOnCopperLayer() const
177 {
178 return IsCopperLayer( GetLayer() );
179 }
180
181 virtual bool HasHole() const
182 {
183 return false;
184 }
185
186 virtual bool HasDrilledHole() const
187 {
188 return false;
189 }
190
198 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
199 {
200 return false;
201 }
202
207
223 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
224 FLASHING aFlash = FLASHING::DEFAULT ) const;
225
226 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
227
233 virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
234
236
238
244 void SetUuidDirect( const KIID& aUuid );
245
247
248 void SetUuid( const KIID& aUuid );
249 void ResetUuid() { SetUuid( KIID() ); }
250
256 virtual void RemapKIIDs( const std::map<KIID, KIID>& aIdMap ) {}
257
259 void SetFPRelativePosition( const VECTOR2I& aPos );
260
266 virtual bool HasLineStroke() const { return false; }
267
276 virtual bool IsLayerAgnostic() const { return false; }
277
285 virtual bool FitsEnabledLayers( const LSET& aEnabledLayers, int aCopperLayerCount ) const;
286
287 virtual STROKE_PARAMS GetStroke() const;
288 virtual void SetStroke( const STROKE_PARAMS& aStroke );
289
290 const KIFONT::METRICS& GetFontMetrics() const;
291
295 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
296
300 virtual int BoardLayerCount() const;
301
305 virtual int BoardCopperLayerCount() const;
306
310 virtual LSET BoardLayerSet() const;
311
315 virtual LSET GetLayerSet() const
316 {
317 if( m_layer == UNDEFINED_LAYER )
318 return LSET();
319 else
320 return LSET( { m_layer } );
321 }
322
323 virtual void SetLayerSet( const LSET& aLayers )
324 {
325 if( aLayers.count() == 1 )
326 {
327 SetLayer( aLayers.Seq()[0] );
328 return;
329 }
330
332
333 // Derived classes which support multiple layers must implement this
334 }
335
336 bool IsSideSpecific() const;
337
343 virtual void SetLayer( PCB_LAYER_ID aLayer )
344 {
345 m_layer = aLayer;
346 }
347
354 virtual BOARD_ITEM* Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
355
366 void SwapItemData( BOARD_ITEM* aImage );
367
377 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
378 {
379 return m_layer == aLayer;
380 }
381
382 virtual bool IsKnockout() const { return m_isKnockout; }
383 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
384
385 bool IsLocked() const override;
386 void SetLocked( bool aLocked ) override { m_isLocked = aLocked; }
387
388 bool IsIndexedInBoard() const { return m_indexedInBoard; }
389
390 int GetMaxError() const;
391
392 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide ) { }
393
397 void DeleteStructure();
398
404 virtual void Move( const VECTOR2I& aMoveVector )
405 {
406 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
407 }
408
414 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
415
427 virtual void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
428 const EDA_ANGLE& aParentRotate )
429 {}
430
435 virtual void OnFootprintTransformed() {}
436
443 virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
444
451 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
452
456 virtual void Normalize() {}
457
463 virtual void NormalizeForCompare() { Normalize(); }
464
468 virtual const BOARD* GetBoard() const;
469 virtual BOARD* GetBoard();
470
475 wxString GetParentAsString() const;
476
482 wxString GetLayerName() const;
483
484 virtual std::vector<int> ViewGetLayers() const override;
485
496 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
497 int aClearance, int aError, ERROR_LOC aErrorLoc,
498 bool ignoreLineWidth = false ) const;
499
512 int aClearance, int aError, ERROR_LOC aErrorLoc,
513 KIGFX::RENDER_SETTINGS* aRenderSettings = nullptr ) const
514 {
515 TransformShapeToPolygon( aBuffer, aLayer, aClearance, aError, aErrorLoc );
516 }
517
518 const std::vector<wxString>* GetEmbeddedFonts() override;
519
523 virtual wxString LayerMaskDescribe() const;
524
525 enum COMPARE_FLAGS : int
526 {
527 DRC = 0x01,
529 };
530
531 struct ptr_cmp
532 {
533 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
534 };
535
536protected:
537 virtual void swapData( BOARD_ITEM* aImage );
538
539protected:
543
544 // Mirrors BOARD identity-cache membership so ~BOARD_ITEM can evict without walking a parent
545 // chain that may already be freed. Maintained by BOARD; clones start detached.
546 mutable bool m_indexedInBoard = false;
547
548 friend class BOARD;
549};
550
552
559{
560public:
562 BOARD_ITEM( nullptr, NOT_USED )
563 {}
564
565 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
566 {
567 return _( "(Deleted Item)" );
568 }
569
570 wxString GetClass() const override
571 {
572 return wxT( "DELETED_BOARD_ITEM" );
573 }
574
575 // pure virtuals:
576 void SetPosition( const VECTOR2I& ) override {}
577 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
578
580 {
581 static DELETED_BOARD_ITEM* item = nullptr;
582
583 if( !item )
584 item = new DELETED_BOARD_ITEM();
585
586 return item;
587 }
588
589 double Similarity( const BOARD_ITEM& aItem ) const override
590 {
591 return ( this == &aItem ) ? 1.0 : 0.0;
592 }
593
594 bool operator==( const BOARD_ITEM& aBoardItem ) const override
595 {
596 return ( this == &aBoardItem );
597 }
598
599 bool operator==( const DELETED_BOARD_ITEM& aOther ) const
600 {
601 return ( this == &aOther );
602 }
603
604#if defined(DEBUG)
605 void Show( int , std::ostream& ) const override {}
606#endif
607};
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:71
@ ZLO_NONE
Definition board_item.h:72
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition board_item.h:74
@ ZLO_FORCE_FLASHED
Definition board_item.h:73
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:83
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:85
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:295
friend class BOARD
Definition board_item.h:548
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void ResetUuidDirect()
Definition board_item.h:246
int GetY() const
Definition board_item.h:126
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:463
virtual void OnFootprintTransformed()
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
Definition board_item.h:435
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:386
virtual STROKE_PARAMS GetStroke() const
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:159
bool m_isKnockout
Definition board_item.h:541
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:540
BOARD_ITEM(const BOARD_ITEM &aOther)
Definition board_item.h:93
virtual void SetLayerSet(const LSET &aLayers)
Definition board_item.h:323
bool m_isLocked
Definition board_item.h:542
bool IsIndexedInBoard() const
Definition board_item.h:388
wxString GetParentAsString() const
For "parent" property.
bool m_indexedInBoard
Definition board_item.h:546
virtual bool IsKnockout() const
Definition board_item.h:382
int GetX() const
Definition board_item.h:120
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:142
void SetY(int aY)
Definition board_item.h:148
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition board_item.h:137
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:404
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:377
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:383
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:343
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:315
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:198
virtual bool IsLayerAgnostic() const
Check if this item's layer set must not be confined to a board's enabled layers.
Definition board_item.h:276
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:511
virtual void swapData(BOARD_ITEM *aImage)
const KIFONT::METRICS & GetFontMetrics() const
~BOARD_ITEM() override
@ INSTANCE_TO_INSTANCE
Definition board_item.h:528
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:206
virtual bool FitsEnabledLayers(const LSET &aEnabledLayers, int aCopperLayerCount) const
Check if a board offering aEnabledLayers can hold this item.
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:233
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
Definition board_item.h:102
void ResetUuid()
Definition board_item.h:249
virtual bool HasDrilledHole() const
Definition board_item.h:186
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:235
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:176
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition board_item.h:266
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition board_item.h:456
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:427
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:392
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
virtual bool HasHole() const
Definition board_item.h:181
virtual void RemapKIIDs(const std::map< KIID, KIID > &aIdMap)
Remap KIIDs this item stores to reference other items (e.g.
Definition board_item.h:256
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
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:565
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:579
wxString GetClass() const override
Return the class name.
Definition board_item.h:570
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:589
VECTOR2I GetPosition() const override
Definition board_item.h:577
void SetPosition(const VECTOR2I &) override
Definition board_item.h:576
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition board_item.h:594
bool operator==(const DELETED_BOARD_ITEM &aOther) const
Definition board_item.h:599
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:46
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:51
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:683
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