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 (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 <layer_ids.h>
32#include <stroke_params.h>
33#include <geometry/eda_angle.h>
34
35class BOARD;
37class SHAPE_POLY_SET;
38class SHAPE_SEGMENT;
39class PCB_BASE_FRAME;
40class SHAPE;
41class PCB_GROUP;
42class FOOTPRINT;
43
44
58{
62};
63
64
70class BOARD_ITEM : public EDA_ITEM
71{
72public:
73 BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype, PCB_LAYER_ID aLayer = F_Cu ) :
74 EDA_ITEM( aParent, idtype ),
75 m_layer( aLayer ),
76 m_isKnockout( false ),
77 m_isLocked( false ),
78 m_group( nullptr )
79 {
80 }
81
83
84 void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
85 PCB_GROUP* GetParentGroup() const { return m_group; }
86
87 // Do not create a copy constructor & operator=.
88 // The ones generated by the compiler are adequate.
89 int GetX() const
90 {
92 return p.x;
93 }
94
95 int GetY() const
96 {
98 return p.y;
99 }
100
106 virtual VECTOR2I GetCenter() const
107 {
108 return GetBoundingBox().GetCenter();
109 }
110
111 void SetX( int aX )
112 {
113 VECTOR2I p( aX, GetY() );
114 SetPosition( p );
115 }
116
117 void SetY( int aY )
118 {
119 VECTOR2I p( GetX(), aY );
120 SetPosition( p );
121 }
122
128 virtual bool IsConnected() const
129 {
130 return false;
131 }
132
136 virtual bool IsOnCopperLayer() const
137 {
138 return IsCopperLayer( GetLayer() );
139 }
140
141 virtual bool HasHole() const
142 {
143 return false;
144 }
145
146 virtual bool IsTented() const
147 {
148 return false;
149 }
150
155
171 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
172 FLASHING aFlash = FLASHING::DEFAULT ) const;
173
174 virtual std::shared_ptr<SHAPE_SEGMENT> GetEffectiveHoleShape() const;
175
177
179
181 void SetFPRelativePosition( const VECTOR2I& aPos );
182
188 virtual bool HasLineStroke() const { return false; }
189
190 virtual STROKE_PARAMS GetStroke() const;
191 virtual void SetStroke( const STROKE_PARAMS& aStroke );
192
196 virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
197
201 virtual LSET GetLayerSet() const
202 {
203 if( m_layer == UNDEFINED_LAYER )
204 return LSET();
205 else
206 return LSET( m_layer );
207 }
208
209 virtual void SetLayerSet( LSET aLayers )
210 {
211 if( aLayers.count() == 1 )
212 {
213 SetLayer( aLayers.Seq()[0] );
214 return;
215 }
216
217 wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
218
219 // Derived classes which support multiple layers must implement this
220 }
221
230 virtual void SetLayer( PCB_LAYER_ID aLayer )
231 {
232 m_layer = aLayer;
233 }
234
238 virtual BOARD_ITEM* Duplicate() const;
239
250 void SwapItemData( BOARD_ITEM* aImage );
251
261 virtual bool IsOnLayer( PCB_LAYER_ID aLayer, bool aIncludeCourtyards = false ) const
262 {
263 return m_layer == aLayer;
264 }
265
266 virtual bool IsKnockout() const { return m_isKnockout; }
267 virtual void SetIsKnockout( bool aKnockout ) { m_isKnockout = aKnockout; }
268
269 virtual bool IsLocked() const;
270 virtual void SetLocked( bool aLocked ) { m_isLocked = aLocked; }
271
275 void DeleteStructure();
276
282 virtual void Move( const VECTOR2I& aMoveVector )
283 {
284 wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
285 }
286
292 virtual void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle );
293
300 virtual void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight );
301
305 virtual const BOARD* GetBoard() const;
306 virtual BOARD* GetBoard();
307
313 wxString GetLayerName() const;
314
315 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
316
327 virtual void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer,
328 int aClearance, int aError, ERROR_LOC aErrorLoc,
329 bool ignoreLineWidth = false ) const;
330
331 struct ptr_cmp
332 {
333 bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
334 };
335
336protected:
340 virtual wxString layerMaskDescribe() const;
341
342 virtual void swapData( BOARD_ITEM* aImage );
343
344protected:
347
349
351};
352
353#ifndef SWIG
355#endif
356
357
364{
365public:
367 BOARD_ITEM( nullptr, NOT_USED )
368 {}
369
370 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
371 {
372 return _( "(Deleted Item)" );
373 }
374
375 wxString GetClass() const override
376 {
377 return wxT( "DELETED_BOARD_ITEM" );
378 }
379
380 // pure virtuals:
381 void SetPosition( const VECTOR2I& ) override {}
382 VECTOR2I GetPosition() const override { return VECTOR2I( 0, 0 ); }
383
385 {
386 static DELETED_BOARD_ITEM* item = nullptr;
387
388 if( !item )
389 item = new DELETED_BOARD_ITEM();
390
391 return item;
392 }
393
394#if defined(DEBUG)
395 void Show( int , std::ostream& ) const override {}
396#endif
397};
398
399
400#endif /* BOARD_ITEM_STRUCT_H */
ZONE_LAYER_OVERRIDE
Conditionally flashed vias and pads that interact with zones of different priority can be very squirr...
Definition: board_item.h:58
@ ZLO_NONE
Definition: board_item.h:59
@ ZLO_FORCE_NO_ZONE_CONNECTION
Definition: board_item.h:61
@ ZLO_FORCE_FLASHED
Definition: board_item.h:60
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:71
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition: board_item.h:73
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:196
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:84
int GetY() const
Definition: board_item.h:95
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:151
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:167
virtual void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:288
virtual STROKE_PARAMS GetStroke() const
Definition: board_item.cpp:83
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:128
bool m_isKnockout
Definition: board_item.h:346
virtual void SetLocked(bool aLocked)
Definition: board_item.h:270
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:85
PCB_GROUP * m_group
Definition: board_item.h:350
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: board_item.cpp:89
PCB_LAYER_ID m_layer
Definition: board_item.h:345
bool m_isLocked
Definition: board_item.h:348
virtual bool IsKnockout() const
Definition: board_item.h:266
int GetX() const
Definition: board_item.h:89
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.
Definition: board_item.cpp:197
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
Definition: board_item.cpp:282
void SetX(int aX)
Definition: board_item.h:111
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:185
void SetY(int aY)
Definition: board_item.h:117
virtual bool IsTented() const
Definition: board_item.h:146
virtual VECTOR2I GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:106
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:282
virtual void SetIsKnockout(bool aKnockout)
Definition: board_item.h:267
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:230
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:220
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:44
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:240
VECTOR2I GetFPRelativePosition() const
Definition: board_item.cpp:254
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:201
virtual void swapData(BOARD_ITEM *aImage)
Definition: board_item.cpp:162
void SetFPRelativePosition(const VECTOR2I &aPos)
Definition: board_item.cpp:268
static VECTOR2I ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:154
virtual bool IsLocked() const
Definition: board_item.cpp:72
virtual bool IsOnLayer(PCB_LAYER_ID aLayer, bool aIncludeCourtyards=false) const
Test to see if this object is on the given layer.
Definition: board_item.h:261
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:176
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:140
virtual bool IsOnCopperLayer() const
Definition: board_item.h:136
virtual bool HasLineStroke() const
Check if this item has line stoke properties.
Definition: board_item.h:188
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:107
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:95
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:230
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:209
virtual bool HasHole() const
Definition: board_item.h:141
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:270
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:364
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:384
wxString GetClass() const override
Return the class name.
Definition: board_item.h:375
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: board_item.h:370
VECTOR2I GetPosition() const override
Definition: board_item.h:382
void SetPosition(const VECTOR2I &) override
Definition: board_item.h:381
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:232
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:233
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:73
virtual wxString GetClass() const =0
Return the class name.
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:536
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:124
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:831
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
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:693
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:205
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:588