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;
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 virtual void CopyFrom( const BOARD_ITEM* aOther );
94
95 bool IsGroupableType() const;
96
97 // Do not create a copy constructor & operator=.
98 // The ones generated by the compiler are adequate.
99 int GetX() const
100 {
101 VECTOR2I p = GetPosition();
102 return p.x;
103 }
104
105 int GetY() const
106 {
107 VECTOR2I p = GetPosition();
108 return p.y;
109 }
110
116 virtual VECTOR2I GetCenter() const
117 {
118 return GetBoundingBox().GetCenter();
119 }
120
121 void SetX( int aX )
122 {
123 VECTOR2I p( aX, GetY() );
124 SetPosition( p );
125 }
126
127 void SetY( int aY )
128 {
129 VECTOR2I p( GetX(), aY );
130 SetPosition( p );
131 }
132
138 virtual bool IsConnected() const
139 {
140 return false;
141 }
142
149 virtual double Similarity( const BOARD_ITEM& aItem ) const = 0;
150 virtual bool operator==( const BOARD_ITEM& aItem ) const = 0;
151
155 virtual bool IsOnCopperLayer() const
156 {
157 return IsCopperLayer( GetLayer() );
158 }
159
160 virtual bool HasHole() const
161 {
162 return false;
163 }
164
165 virtual bool HasDrilledHole() const
166 {
167 return false;
168 }
169
177 virtual bool IsTented( PCB_LAYER_ID aLayer ) const
178 {
179 return false;
180 }
181
186
202 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
203 FLASHING aFlash = FLASHING::DEFAULT ) const;
204
205 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
206
212 virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
213
215
217
219 void SetFPRelativePosition( const VECTOR2I& aPos );
220
226 virtual bool HasLineStroke() const { return false; }
227
228 virtual STROKE_PARAMS GetStroke() const;
229 virtual void SetStroke( const STROKE_PARAMS& aStroke );
230
231 const KIFONT::METRICS& GetFontMetrics() const;
232
236 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
237
241 virtual int BoardLayerCount() const;
242
246 virtual int BoardCopperLayerCount() const;
247
251 virtual LSET BoardLayerSet() const;
252
256 virtual LSET GetLayerSet() const
257 {
258 if( m_layer == UNDEFINED_LAYER )
259 return LSET();
260 else
261 return LSET( { m_layer } );
262 }
263
264 virtual void SetLayerSet( const LSET& aLayers )
265 {
266 if( aLayers.count() == 1 )
267 {
268 SetLayer( aLayers.Seq()[0] );
269 return;
270 }
271
272 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
273
274 // Derived classes which support multiple layers must implement this
275 }
276
277 bool IsSideSpecific() const;
278
284 virtual void SetLayer( PCB_LAYER_ID aLayer )
285 {
286 m_layer = aLayer;
287 }
288
295 virtual BOARD_ITEM* Duplicate( bool addToParentGroup, BOARD_COMMIT* aCommit = nullptr ) const;
296
307 void SwapItemData( BOARD_ITEM* aImage );
308
318 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
319 {
320 return m_layer == aLayer;
321 }
322
323 virtual bool IsKnockout() const { return m_isKnockout; }
324 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
325
326 bool IsLocked() const override;
327 void SetLocked( bool aLocked ) override { m_isLocked = aLocked; }
328
329 int GetMaxError() const;
330
331 virtual void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide ) { }
332
336 void DeleteStructure();
337
343 virtual void Move( const VECTOR2I& aMoveVector )
344 {
345 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
346 }
347
353 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
354
361 virtual void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
362
369 virtual void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection );
370
374 virtual void Normalize() {}
375
381 virtual void NormalizeForCompare() { Normalize(); }
382
386 virtual const BOARD* GetBoard() const;
387 virtual BOARD* GetBoard();
388
393 wxString GetParentAsString() const;
394
400 wxString GetLayerName() const;
401
402 virtual std::vector<int> ViewGetLayers() const override;
403
414 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
415 int aClearance, int aError, ERROR_LOC aErrorLoc,
416 bool ignoreLineWidth = false ) const;
417
430 int aClearance, int aError, ERROR_LOC aErrorLoc,
431 KIGFX::RENDER_SETTINGS* aRenderSettings = nullptr ) const
432 {
433 TransformShapeToPolygon( aBuffer, aLayer, aClearance, aError, aErrorLoc );
434 }
435
436 const std::vector<wxString>* GetEmbeddedFonts() override;
437
441 virtual wxString LayerMaskDescribe() const;
442
443 enum COMPARE_FLAGS : int
444 {
445 DRC = 0x01,
447 };
448
449 struct ptr_cmp
450 {
451 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
452 };
453
454protected:
455 virtual void swapData( BOARD_ITEM* aImage );
456
457protected:
460
462};
463
464#ifndef SWIG
466#endif
467
468
475{
476public:
478 BOARD_ITEM( nullptr, NOT_USED )
479 {}
480
481 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
482 {
483 return _( "(Deleted Item)" );
484 }
485
486 wxString GetClass() const override
487 {
488 return wxT( "DELETED_BOARD_ITEM" );
489 }
490
491 // pure virtuals:
492 void SetPosition( const VECTOR2I& ) override {}
493 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
494
496 {
497 static DELETED_BOARD_ITEM* item = nullptr;
498
499 if( !item )
500 item = new DELETED_BOARD_ITEM();
501
502 return item;
503 }
504
505 double Similarity( const BOARD_ITEM& aItem ) const override
506 {
507 return ( this == &aItem ) ? 1.0 : 0.0;
508 }
509
510 bool operator==( const BOARD_ITEM& aBoardItem ) const override
511 {
512 return ( this == &aBoardItem );
513 }
514
515 bool operator==( const DELETED_BOARD_ITEM& aOther ) const
516 {
517 return ( this == &aOther );
518 }
519
520#if defined(DEBUG)
521 void Show( int , std::ostream& ) const override {}
522#endif
523};
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:236
int GetY() const
Definition board_item.h:105
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:381
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:327
virtual STROKE_PARAMS GetStroke() const
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:138
bool m_isKnockout
Definition board_item.h:459
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)
PCB_LAYER_ID m_layer
Definition board_item.h:458
virtual void SetLayerSet(const LSET &aLayers)
Definition board_item.h:264
bool m_isLocked
Definition board_item.h:461
wxString GetParentAsString() const
For "parent" property.
virtual bool IsKnockout() const
Definition board_item.h:323
int GetX() const
Definition board_item.h:99
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:121
void SetY(int aY)
Definition board_item.h:127
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition board_item.h:116
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:343
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:318
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:324
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:284
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:256
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:177
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:429
virtual void swapData(BOARD_ITEM *aImage)
const KIFONT::METRICS & GetFontMetrics() const
@ INSTANCE_TO_INSTANCE
Definition board_item.h:446
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:185
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:212
virtual bool HasDrilledHole() const
Definition board_item.h:165
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:214
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:155
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition board_item.h:226
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition board_item.h:374
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:331
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
virtual bool HasHole() const
Definition board_item.h:160
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
constexpr const Vec GetCenter() const
Definition box2.h:230
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition board_item.h:481
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:495
wxString GetClass() const override
Return the class name.
Definition board_item.h:486
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:505
VECTOR2I GetPosition() const override
Definition board_item.h:493
void SetPosition(const VECTOR2I &) override
Definition board_item.h:492
bool operator==(const BOARD_ITEM &aBoardItem) const override
Definition board_item.h:510
bool operator==(const DELETED_BOARD_ITEM &aOther) const
Definition board_item.h:515
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
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
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.
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.
#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
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:185
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:677
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
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
#define DECLARE_ENUM_TO_WXANY(type)
Definition property.h:787
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:78
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695