KiCad PCB EDA Suite
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 (C) 1992-2022 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#ifndef BOARD_ITEM_STRUCT_H
26#define BOARD_ITEM_STRUCT_H
27
28
29#include <eda_item.h>
30#include <eda_units.h>
31#include <gr_basic.h>
32#include <layer_ids.h>
34#include <stroke_params.h>
35#include <geometry/eda_angle.h>
36
37class BOARD;
39class SHAPE_POLY_SET;
40class SHAPE_SEGMENT;
41class PCB_BASE_FRAME;
42class SHAPE;
43class PCB_GROUP;
44
45
51class BOARD_ITEM : public EDA_ITEM
52{
53public:
54 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
55 EDA_ITEM( aParent, idtype ),
56 m_layer( aLayer ),
57 m_isKnockout( false ),
58 m_isLocked( false ),
59 m_group( nullptr )
60 {
61 }
62
63 void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
64 PCB_GROUP* GetParentGroup() const { return m_group; }
65
66 // Do not create a copy constructor & operator=.
67 // The ones generated by the compiler are adequate.
68 int GetX() const
69 {
71 return p.x;
72 }
73
74 int GetY() const
75 {
77 return p.y;
78 }
79
85 virtual VECTOR2I GetCenter() const
86 {
87 return GetBoundingBox().GetCenter();
88 }
89
90 void SetX( int aX )
91 {
92 VECTOR2I p( aX, GetY() );
93 SetPosition( p );
94 }
95
96 void SetY( int aY )
97 {
98 VECTOR2I p( GetX(), aY );
99 SetPosition( p );
100 }
101
107 virtual bool IsConnected() const
108 {
109 return false;
110 }
111
115 virtual bool IsOnCopperLayer() const
116 {
117 return IsCopperLayer( GetLayer() );
118 }
119
120 virtual bool HasHole() const
121 {
122 return false;
123 }
124
125 virtual bool IsTented() const
126 {
127 return false;
128 }
129
134
147 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
148 FLASHING aFlash = FLASHING::DEFAULT ) const;
149
150 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
151
153
155
161 virtual bool HasLineStroke() const { return false; }
162
163 virtual STROKE_PARAMS GetStroke() const;
164 virtual void SetStroke( const STROKE_PARAMS& aStroke );
165
169 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
170
174 virtual LSET GetLayerSet() const
175 {
176 if( m_layer == UNDEFINED_LAYER )
177 return LSET();
178 else
179 return LSET( m_layer );
180 }
181
182 virtual void SetLayerSet( LSET aLayers )
183 {
184 if( aLayers.count() == 1 )
185 {
186 SetLayer( aLayers.Seq()[0] );
187 return;
188 }
189
190 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
191
192 // Derived classes which support multiple layers must implement this
193 }
194
203 virtual void SetLayer( PCB_LAYER_ID aLayer )
204 {
205 m_layer = aLayer;
206 }
207
211 virtual BOARD_ITEM* Duplicate() const;
212
223 virtual void SwapData( BOARD_ITEM* aImage );
224
234 virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
235 {
236 return m_layer == aLayer;
237 }
238
239 virtual bool IsKnockout() const { return m_isKnockout; }
240 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
241
242 virtual bool IsLocked() const;
243 virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; }
244
248 void DeleteStructure();
249
255 virtual void Move( const VECTOR2I& aMoveVector )
256 {
257 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
258 }
259
265 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
266
273 virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
274
278 virtual const BOARD* GetBoard() const;
279 virtual BOARD* GetBoard();
280
286 wxString GetLayerName() const;
287
288 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
289
302 virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
303 PCB_LAYER_ID aLayer, int aClearanceValue,
304 int aError, ERROR_LOC aErrorLoc,
305 bool ignoreLineWidth = false ) const;
306
307 struct ptr_cmp
308 {
309 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
310 };
311
312protected:
316 virtual wxString layerMaskDescribe() const;
317
318protected:
321
323
325};
326
327#ifndef SWIG
329#endif
330
331
338{
339public:
341 BOARD_ITEM( nullptr, NOT_USED )
342 {}
343
344 wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override
345 {
346 return _( "(Deleted Item)" );
347 }
348
349 wxString GetClass() const override
350 {
351 return wxT( "DELETED_BOARD_ITEM" );
352 }
353
354 // pure virtuals:
355 void SetPosition( const VECTOR2I& ) override {}
356 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
357
359 {
360 static DELETED_BOARD_ITEM* item = nullptr;
361
362 if( !item )
363 item = new DELETED_BOARD_ITEM();
364
365 return item;
366 }
367
368#if defined(DEBUG)
369 void Show( int , std::ostream& ) const override {}
370#endif
371};
372
373
374#endif /* BOARD_ITEM_STRUCT_H */
DECLARE_ENUM_TO_WXANY(PCB_LAYER_ID)
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:52
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition: board_item.h:54
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:169
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:63
int GetY() const
Definition: board_item.h:74
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:144
virtual void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:234
virtual STROKE_PARAMS GetStroke() const
Definition: board_item.cpp:76
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:107
bool m_isKnockout
Definition: board_item.h:320
virtual void SetLocked(bool aLocked)
Definition: board_item.h:243
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:64
PCB_GROUP * m_group
Definition: board_item.h:324
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: board_item.cpp:82
PCB_LAYER_ID m_layer
Definition: board_item.h:319
bool m_isLocked
Definition: board_item.h:322
virtual bool IsKnockout() const
Definition: board_item.h:239
int GetX() const
Definition: board_item.h:68
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
Definition: board_item.cpp:228
void SetX(int aX)
Definition: board_item.h:90
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:160
void SetY(int aY)
Definition: board_item.h:96
virtual bool IsTented() const
Definition: board_item.h:125
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:85
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:255
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:234
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:240
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:203
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:197
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:37
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:174
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:155
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:133
virtual bool IsLocked() const
Definition: board_item.cpp:65
BOARD_ITEM_CONTAINER * GetParentFootprint() const
Definition: board_item.cpp:217
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:152
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: board_item.cpp:133
virtual bool IsOnCopperLayer() const
Definition: board_item.h:115
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition: board_item.h:161
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
Definition: board_item.cpp:172
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:100
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:88
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:207
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:182
virtual bool HasHole() const
Definition: board_item.h:120
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
const Vec GetCenter() const
Definition: box2.h:195
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: board_item.h:338
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:358
wxString GetClass() const override
Return the class name.
Definition: board_item.h:349
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: board_item.h:344
VECTOR2I GetPosition() const override
Definition: board_item.h:356
void SetPosition(const VECTOR2I &) override
Definition: board_item.h:355
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:263
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:264
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
virtual wxString GetClass() const =0
Return the class name.
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:510
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
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:123
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
#define _(s)
a few functions useful in geometry calculations.
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:823
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
@ F_Cu
Definition: layer_ids.h:64
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:182
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< int > VECTOR2I
Definition: vector2d.h:618