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-2020 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 <convert_to_biu.h>
32 #include <gr_basic.h>
33 #include <layer_ids.h>
35 
36 class BOARD;
38 class SHAPE_POLY_SET;
39 class PCB_BASE_FRAME;
40 class SHAPE;
41 class PCB_GROUP;
42 
43 
49 class BOARD_ITEM : public EDA_ITEM
50 {
51 public:
52  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
53  EDA_ITEM( aParent, idtype ),
54  m_layer( F_Cu ),
55  m_group( nullptr )
56  {
57  }
58 
59  void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
60  PCB_GROUP* GetParentGroup() const { return m_group; }
61 
62  // Do not create a copy constructor & operator=.
63  // The ones generated by the compiler are adequate.
64  int GetX() const
65  {
66  wxPoint p = GetPosition();
67  return p.x;
68  }
69 
70  int GetY() const
71  {
72  wxPoint p = GetPosition();
73  return p.y;
74  }
75 
81  virtual wxPoint GetCenter() const
82  {
83  return GetBoundingBox().GetCenter();
84  }
85 
86  void SetX( int aX )
87  {
88  wxPoint p( aX, GetY() );
89  SetPosition( p );
90  }
91 
92  void SetY( int aY )
93  {
94  wxPoint p( GetX(), aY );
95  SetPosition( p );
96  }
97 
103  virtual bool IsConnected() const
104  {
105  return false;
106  }
107 
111  virtual bool IsOnCopperLayer() const
112  {
113  return IsCopperLayer( GetLayer() );
114  }
115 
119  static wxPoint ZeroOffset;
120 
133  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
134  FLASHING aFlash = FLASHING::DEFAULT ) const;
135 
137 
139 
143  virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
144 
148  virtual LSET GetLayerSet() const { return LSET( m_layer ); }
149  virtual void SetLayerSet( LSET aLayers )
150  {
151  wxFAIL_MSG( wxT( "Attempted to SetLayerSet() on a single-layer object." ) );
152 
153  // Derived classes which support multiple layers must implement this
154  }
155 
164  virtual void SetLayer( PCB_LAYER_ID aLayer )
165  {
166  m_layer = aLayer;
167  }
168 
172  virtual BOARD_ITEM* Duplicate() const;
173 
184  virtual void SwapData( BOARD_ITEM* aImage );
185 
195  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
196  {
197  return m_layer == aLayer;
198  }
199 
205  bool IsTrack() const
206  {
207  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
208  }
209 
213  virtual bool IsLocked() const;
214 
218  virtual void SetLocked( bool aLocked )
219  {
220  SetState( LOCKED, aLocked );
221  }
222 
226  void DeleteStructure();
227 
233  virtual void Move( const wxPoint& aMoveVector )
234  {
235  wxFAIL_MSG( wxT( "virtual BOARD_ITEM::Move called for " ) + GetClass() );
236  }
237 
238  void Move( const VECTOR2I& aMoveVector )
239  {
240  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
241  }
242 
249  virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
250 
251  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
252  {
253  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
254  }
255 
262  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight );
263 
264  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
265  {
266  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
267  }
268 
272  virtual const BOARD* GetBoard() const;
273  virtual BOARD* GetBoard();
274 
280  wxString GetLayerName() const;
281 
282  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
283 
296  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
297  PCB_LAYER_ID aLayer, int aClearanceValue,
298  int aError, ERROR_LOC aErrorLoc,
299  bool ignoreLineWidth = false ) const;
300 
301  struct ptr_cmp
302  {
303  bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
304  };
305 
306 protected:
311  virtual wxString layerMaskDescribe() const;
312 
315 };
316 
317 #ifndef SWIG
319 #endif
320 
321 
328 {
329 public:
331  BOARD_ITEM( nullptr, NOT_USED )
332  {}
333 
334  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override
335  {
336  return _( "(Deleted Item)" );
337  }
338 
339  wxString GetClass() const override
340  {
341  return wxT( "DELETED_BOARD_ITEM" );
342  }
343 
344  // pure virtuals:
345  void SetPosition( const wxPoint& ) override {}
346  wxPoint GetPosition() const override { return wxPoint(0, 0); }
347 
349  {
350  static DELETED_BOARD_ITEM* item = nullptr;
351 
352  if( !item )
353  item = new DELETED_BOARD_ITEM();
354 
355  return item;
356  }
357 
358 #if defined(DEBUG)
359  void Show( int , std::ostream& ) const override {}
360 #endif
361 };
362 
363 
364 #endif /* BOARD_ITEM_STRUCT_H */
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:60
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:164
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:252
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
wxString GetClass() const override
Return the class name.
Definition: board_item.h:339
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Rotate this object.
Definition: board_item.cpp:202
wxPoint GetPosition() const override
Definition: board_item.h:346
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
the 3d code uses this value
Definition: typeinfo.h:79
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:120
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:128
bool IsTrack() const
Test to see if this object is a track or via (or microvia).
Definition: board_item.h:205
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:218
virtual wxPoint GetPosition() const
Definition: eda_item.h:251
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: board_item.h:327
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:149
virtual bool IsLocked() const
Definition: board_item.cpp:64
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:181
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
static wxPoint ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
Definition: board_item.h:119
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
DECLARE_ENUM_TO_WXANY(PCB_LAYER_ID)
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:139
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: board_item.h:334
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:87
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:208
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:141
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
int GetY() const
Definition: board_item.h:70
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:195
virtual void Move(const wxPoint &aMoveVector)
Move this object.
Definition: board_item.h:233
Represent a set of closed polygons.
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:348
#define LOCKED
Pcbnew: locked from movement and deletion.
void SetY(int aY)
Definition: board_item.h:92
#define _(s)
PCB_GROUP * m_group
Definition: board_item.h:314
virtual wxPoint GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:81
a few functions useful in geometry calculations.
void SetPosition(const wxPoint &) override
Definition: board_item.h:345
An abstract shape on 2D plane.
Definition: shape.h:116
void Move(const VECTOR2I &aMoveVector)
Definition: board_item.h:238
void SetX(int aX)
Definition: board_item.h:86
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:808
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:153
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
Definition: board_item.h:52
EDA_UNITS
Definition: eda_units.h:38
virtual wxString GetClass() const =0
Return the class name.
int GetX() const
Definition: board_item.h:64
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:166
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Definition: layer_ids.h:71
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
PCB_LAYER_ID m_layer
Definition: board_item.h:313
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:103
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
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:156
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
const wxPoint GetCenter() const
Definition: eda_rect.h:113
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:136
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: board_item.h:264
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:75
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:143
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual bool IsOnCopperLayer() const
Definition: board_item.h:111
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:148
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
Definition: board_item.h:251
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:144
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
BOARD_ITEM_CONTAINER * GetParentFootprint() const
Definition: board_item.cpp:191
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:59