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#include "drc/drc_rule.h"
37
38class BOARD;
41class BOARD_COMMIT;
42class SHAPE_POLY_SET;
43class SHAPE_SEGMENT;
44class PCB_BASE_FRAME;
45class SHAPE;
46class PCB_GROUP;
47class FOOTPRINT;
48namespace KIGFX
49{
50 class RENDER_SETTINGS;
51};
52
53namespace KIFONT
54{
55class METRICS;
56}
57
58
77
83class BOARD_ITEM : public EDA_ITEM
84{
85public:
86 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
87 EDA_ITEM( aParent, idtype, false, true ),
88 m_layer( aLayer ),
89 m_isKnockout( false ),
90 m_isLocked( false )
91 {
92 }
93
94 BOARD_ITEM( const BOARD_ITEM& aOther ) :
95 EDA_ITEM( aOther ),
96 m_layer( aOther.m_layer ),
97 m_isKnockout( aOther.m_isKnockout ),
98 m_isLocked( aOther.m_isLocked )
99 {
100 // Cache membership is owned by BOARD: clones start detached from any board index
101 }
102
104 {
105 if( this == &aOther )
106 return *this;
107
108 EDA_ITEM::operator=( aOther );
109 m_layer = aOther.m_layer;
110 m_isKnockout = aOther.m_isKnockout;
111 m_isLocked = aOther.m_isLocked;
112 // Owner stays with the target, do not copy it
113 return *this;
114 }
115
116 // A default move would copy the owner. Do not move it.
117 BOARD_ITEM( BOARD_ITEM&& aOther ) :
118 BOARD_ITEM( static_cast<const BOARD_ITEM&>( aOther ) )
119 {
120 }
121
123 {
124 return operator=( static_cast<const BOARD_ITEM&>( aOther ) );
125 }
126
127 ~BOARD_ITEM() override;
128
129 virtual void CopyFrom( const BOARD_ITEM* aOther );
130
131 bool IsGroupableType() const;
132
133 int GetX() const
134 {
135 VECTOR2I p = GetPosition();
136 return p.x;
137 }
138
139 int GetY() const
140 {
141 VECTOR2I p = GetPosition();
142 return p.y;
143 }
144
150 virtual VECTOR2I GetCenter() const
151 {
152 return GetBoundingBox().GetCenter();
153 }
154
155 void SetX( int aX )
156 {
157 VECTOR2I p( aX, GetY() );
158 SetPosition( p );
159 }
160
161 void SetY( int aY )
162 {
163 VECTOR2I p( GetX(), aY );
164 SetPosition( p );
165 }
166
172 virtual bool IsConnected() const
173 {
174 return false;
175 }
176
183 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
184 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
185
189 virtual bool IsOnCopperLayer() const
190 {
191 if( IsSingleLayerType( Type() ) )
192 {
193 return IsCopperLayer( GetLayer() );
194 }
195 else
196 {
197 for( PCB_LAYER_ID layer : GetLayerSet() )
198 {
199 if( IsCopperLayer( layer ) )
200 return true;
201 }
202
203 return false;
204 }
205 }
206
207 virtual bool HasHole() const
208 {
209 return false;
210 }
211
212 virtual bool HasDrilledHole() const
213 {
214 return false;
215 }
216
224 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
225 {
226 return false;
227 }
228
233
252 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
254 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const;
255
256 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
257 DRC_CONSTRAINT_T aUsage = NULL_CONSTRAINT ) const;
258
264 virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
265
267
269
275 void SetUuidDirect( const KIID& aUuid );
276
278
279 void SetUuid( const KIID& aUuid );
280 void ResetUuid() { SetUuid( KIID() ); }
281
287 virtual void RemapKIIDs( const std::map<KIID, KIID>& aIdMap ) {}
288
290 void SetFPRelativePosition( const VECTOR2I& aPos );
291
297 virtual bool HasLineStroke() const { return false; }
298
307 virtual bool IsLayerAgnostic() const { return false; }
308
316 virtual bool FitsEnabledLayers( const LSET& aEnabledLayers, int aCopperLayerCount ) const;
317
318 virtual STROKE_PARAMS GetStroke() const;
319 virtual void SetStroke( const STROKE_PARAMS& aStroke );
320
321 const KIFONT::METRICS& GetFontMetrics() const;
322
326 virtual PCB_LAYER_ID GetLayer() const;
327
331 virtual int BoardLayerCount() const;
332
336 virtual int BoardCopperLayerCount() const;
337
341 virtual LSET BoardLayerSet() const;
342
346 virtual LSET GetLayerSet() const
347 {
348 if( m_layer == UNDEFINED_LAYER )
349 return LSET();
350 else
351 return LSET( { m_layer } );
352 }
353
354 virtual void SetLayerSet( const LSET& aLayers )
355 {
356 if( aLayers.count() == 1 )
357 {
358 SetLayer( aLayers.Seq()[0] );
359 return;
360 }
361
363
364 // Derived classes which support multiple layers must implement this
365 }
366
367 bool IsSideSpecific() const;
368
374 virtual void SetLayer( PCB_LAYER_ID aLayer )
375 {
376 m_layer = aLayer;
377 }
378
385 virtual BOARD_ITEM* Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
386
397 void SwapItemData( BOARD_ITEM* aImage );
398
408 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
409 {
410 return m_layer == aLayer;
411 }
412
413 virtual bool IsKnockout() const { return m_isKnockout; }
414 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
415
416 bool IsLocked() const override;
417 void SetLocked( bool aLocked ) override { m_isLocked = aLocked; }
418
419 bool IsIndexedInBoard() const { return m_boardCacheOwner != nullptr; }
420
421 int GetMaxError() const;
422
423 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide ) { }
424
428 void DeleteStructure();
429
435 virtual void Move( const VECTOR2I& aMoveVector )
436 {
437 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
438 }
439
445 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
446
458 virtual void OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
459 const EDA_ANGLE& aParentRotate )
460 {}
461
466 virtual void OnFootprintTransformed() {}
467
474 virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
475
482 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
483
487 virtual void Normalize() {}
488
494 virtual void NormalizeForCompare() { Normalize(); }
495
499 virtual const BOARD* GetBoard() const;
500 virtual BOARD* GetBoard();
501
506 wxString GetParentAsString() const;
507
513 wxString GetLayerName() const;
514
515 virtual std::vector<int> ViewGetLayers() const override;
516
527 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
528 int aClearance, int aError, ERROR_LOC aErrorLoc,
529 bool ignoreLineWidth = false ) const;
530
543 int aClearance, int aError, ERROR_LOC aErrorLoc,
544 KIGFX::RENDER_SETTINGS* aRenderSettings = nullptr ) const
545 {
546 TransformShapeToPolygon( aBuffer, aLayer, aClearance, aError, aErrorLoc );
547 }
548
549 const std::vector<wxString>* GetEmbeddedFonts() override;
550
554 virtual wxString LayerMaskDescribe() const;
555
556 enum COMPARE_FLAGS : int
557 {
558 DRC = 0x01,
560 };
561
562 struct ptr_cmp
563 {
564 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
565 };
566
567protected:
568 virtual void swapData( BOARD_ITEM* aImage );
569
570protected:
574
575 // Board that indexed this item, or nullptr. Set only by BOARD. Clones start detached.
576 mutable BOARD* m_boardCacheOwner = nullptr;
577
578 friend class BOARD;
579};
580
582
589{
590public:
592 BOARD_ITEM( nullptr, NOT_USED )
593 {}
594
595 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
596 {
597 return _( "(Deleted Item)" );
598 }
599
600 wxString GetClass() const override
601 {
602 return wxT( "DELETED_BOARD_ITEM" );
603 }
604
605 // pure virtuals:
606 void SetPosition( const VECTOR2I& ) override {}
607 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
608
610 {
611 static DELETED_BOARD_ITEM* item = nullptr;
612
613 if( !item )
614 item = new DELETED_BOARD_ITEM();
615
616 return item;
617 }
618
619 double Similarity( const BOARD_ITEM& aItem ) const override
620 {
621 return ( this == &aItem ) ? 1.0 : 0.0;
622 }
623
624 bool operator==( const BOARD_ITEM& aBoardItem ) const override
625 {
626 return ( this == &aBoardItem );
627 }
628
629 bool operator==( const DELETED_BOARD_ITEM& aOther ) const
630 {
631 return ( this == &aOther );
632 }
633
634#if defined(DEBUG)
635 void Show( int , std::ostream& ) const override {}
636#endif
637};
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:72
@ ZLO_NONE
Definition board_item.h:73
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition board_item.h:75
@ ZLO_FORCE_FLASHED
Definition board_item.h:74
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:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
virtual void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Mirror this object relative to a given horizontal axis the layer is not changed.
friend class BOARD
Definition board_item.h:578
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void ResetUuidDirect()
Definition board_item.h:277
int GetY() const
Definition board_item.h:139
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:494
virtual void OnFootprintTransformed()
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
Definition board_item.h:466
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:417
virtual STROKE_PARAMS GetStroke() const
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:172
bool m_isKnockout
Definition board_item.h:572
BOARD * m_boardCacheOwner
Definition board_item.h:576
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:571
BOARD_ITEM(const BOARD_ITEM &aOther)
Definition board_item.h:94
virtual void SetLayerSet(const LSET &aLayers)
Definition board_item.h:354
bool m_isLocked
Definition board_item.h:573
bool IsIndexedInBoard() const
Definition board_item.h:419
wxString GetParentAsString() const
For "parent" property.
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
virtual bool IsKnockout() const
Definition board_item.h:413
int GetX() const
Definition board_item.h:133
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
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:155
void SetY(int aY)
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:150
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:435
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:408
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:414
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:374
BOARD_ITEM & operator=(BOARD_ITEM &&aOther)
Definition board_item.h:122
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
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.
BOARD_ITEM(BOARD_ITEM &&aOther)
Definition board_item.h:117
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:346
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:224
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:307
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:542
virtual void swapData(BOARD_ITEM *aImage)
const KIFONT::METRICS & GetFontMetrics() const
~BOARD_ITEM() override
@ INSTANCE_TO_INSTANCE
Definition board_item.h:559
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:232
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:264
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
Definition board_item.h:103
void ResetUuid()
Definition board_item.h:280
virtual bool HasDrilledHole() const
Definition board_item.h:212
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:266
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:189
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition board_item.h:297
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition board_item.h:487
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
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:458
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 void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide)
Definition board_item.h:423
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
virtual bool HasHole() const
Definition board_item.h:207
virtual void RemapKIIDs(const std::map< KIID, KIID > &aIdMap)
Remap KIIDs this item stores to reference other items (e.g.
Definition board_item.h:287
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
constexpr const Vec GetCenter() const
Definition box2.h:227
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition board_item.h:595
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:609
wxString GetClass() const override
Return the class name.
Definition board_item.h:600
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:619
VECTOR2I GetPosition() const override
Definition board_item.h:607
void SetPosition(const VECTOR2I &) override
Definition board_item.h:606
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition board_item.h:624
bool operator==(const DELETED_BOARD_ITEM &aOther) const
Definition board_item.h:629
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition eda_item.cpp:488
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:349
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:270
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:607
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
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.
DRC_CONSTRAINT_T
Definition drc_rule.h:49
@ NULL_CONSTRAINT
Definition drc_rule.h:50
#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: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:703
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:30
#define DECLARE_ENUM_TO_WXANY(type)
Definition property.h:838
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
constexpr bool IsSingleLayerType(const KICAD_T aType)
Definition typeinfo.h:506
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:71
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683