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 ) const;
134 
136 
140  virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
141 
145  virtual LSET GetLayerSet() const { return LSET( m_layer ); }
146  virtual void SetLayerSet( LSET aLayers )
147  {
148  wxFAIL_MSG( "Attempted to SetLayerSet() on a single-layer object." );
149 
150  // Derived classes which support multiple layers must implement this
151  }
152 
161  virtual void SetLayer( PCB_LAYER_ID aLayer )
162  {
163  m_layer = aLayer;
164  }
165 
169  virtual BOARD_ITEM* Duplicate() const
170  {
171  EDA_ITEM* dupe = Clone();
172  const_cast<KIID&>( dupe->m_Uuid ) = KIID();
173 
174  return static_cast<BOARD_ITEM*>( dupe );
175  }
176 
187  virtual void SwapData( BOARD_ITEM* aImage );
188 
198  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
199  {
200  return m_layer == aLayer;
201  }
202 
208  bool IsTrack() const
209  {
210  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
211  }
212 
216  virtual bool IsLocked() const;
217 
221  virtual void SetLocked( bool aLocked )
222  {
223  SetState( LOCKED, aLocked );
224  }
225 
229  void DeleteStructure();
230 
236  virtual void Move( const wxPoint& aMoveVector )
237  {
238  wxFAIL_MSG( "virtual BOARD_ITEM::Move called for " + GetClass() );
239  }
240 
241  void Move( const VECTOR2I& aMoveVector )
242  {
243  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
244  }
245 
252  virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
253 
254  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
255  {
256  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
257  }
258 
265  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight );
266 
267  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
268  {
269  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
270  }
271 
275  virtual const BOARD* GetBoard() const;
276  virtual BOARD* GetBoard();
277 
283  wxString GetLayerName() const;
284 
285  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
286 
299  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
300  PCB_LAYER_ID aLayer, int aClearanceValue,
301  int aError, ERROR_LOC aErrorLoc,
302  bool ignoreLineWidth = false ) const;
303 
304  struct ptr_cmp
305  {
306  bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
307  };
308 
309 protected:
314  virtual wxString layerMaskDescribe() const;
315 
318 };
319 
320 #ifndef SWIG
322 #endif
323 
324 
331 {
332 public:
334  BOARD_ITEM( nullptr, NOT_USED )
335  {}
336 
337  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override
338  {
339  return _( "(Deleted Item)" );
340  }
341 
342  wxString GetClass() const override
343  {
344  return wxT( "DELETED_BOARD_ITEM" );
345  }
346 
347  // pure virtuals:
348  void SetPosition( const wxPoint& ) override {}
349  wxPoint GetPosition() const override { return wxPoint(0, 0); }
350 
352  {
353  static DELETED_BOARD_ITEM* item = nullptr;
354 
355  if( !item )
356  item = new DELETED_BOARD_ITEM();
357 
358  return item;
359  }
360 
361 #if defined(DEBUG)
362  void Show( int , std::ostream& ) const override {}
363 #endif
364 };
365 
366 
367 #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:479
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:161
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:253
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:342
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Rotate this object.
Definition: board_item.cpp:177
wxPoint GetPosition() const override
Definition: board_item.h:349
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:118
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:126
bool IsTrack() const
Test to see if this object is a track or via (or microvia).
Definition: board_item.h:208
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:221
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: board_item.h:330
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:146
virtual bool IsLocked() const
Definition: board_item.cpp:64
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
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:83
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:137
Definition: kiid.h:44
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:337
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:85
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:183
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:142
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
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:198
virtual void Move(const wxPoint &aMoveVector)
Move this object.
Definition: board_item.h:236
Represent a set of closed polygons.
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:351
#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:317
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:348
An abstract shape on 2D plane.
Definition: shape.h:116
void Move(const VECTOR2I &aMoveVector)
Definition: board_item.h:241
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:796
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
Definition: board_item.h:52
const KIID m_Uuid
Definition: eda_item.h:475
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:190
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:152
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:100
PCB_LAYER_ID m_layer
Definition: board_item.h:316
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:167
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
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:169
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:142
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:104
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:135
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: board_item.h:267
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:73
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:140
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:145
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
Definition: board_item.h:254
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:59