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>
35 
36 class BOARD;
38 class SHAPE_POLY_SET;
39 class PCB_BASE_FRAME;
40 class SHAPE;
41 class PCB_GROUP;
42 
46 enum class SHAPE_T : int
47 {
48  SEGMENT = 0,
49  RECT,
50  ARC,
51  CIRCLE,
52  POLY,
53  BEZIER,
54  LAST
55 };
56 
57 static inline wxString SHAPE_T_asString( SHAPE_T a )
58 {
59  switch( a )
60  {
61  case SHAPE_T::SEGMENT: return "S_SEGMENT";
62  case SHAPE_T::RECT: return "S_RECT";
63  case SHAPE_T::ARC: return "S_ARC";
64  case SHAPE_T::CIRCLE: return "S_CIRCLE";
65  case SHAPE_T::POLY: return "S_POLYGON";
66  case SHAPE_T::BEZIER: return "S_CURVE";
67  case SHAPE_T::LAST: return "S_LAST"; // Synthetic value, but if we come across it we're
68  // going to want to know.
69  }
70 
71  return wxEmptyString; // Just to quiet GCC.
72 };
73 
74 
80 class BOARD_ITEM : public EDA_ITEM
81 {
82 public:
83  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
84  EDA_ITEM( aParent, idtype ),
85  m_layer( F_Cu ),
86  m_group( nullptr )
87  {
88  }
89 
90  void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
91  PCB_GROUP* GetParentGroup() const { return m_group; }
92 
93  // Do not create a copy constructor & operator=.
94  // The ones generated by the compiler are adequate.
95  int GetX() const
96  {
97  wxPoint p = GetPosition();
98  return p.x;
99  }
100 
101  int GetY() const
102  {
103  wxPoint p = GetPosition();
104  return p.y;
105  }
106 
112  virtual wxPoint GetCenter() const
113  {
114  return GetBoundingBox().GetCenter();
115  }
116 
117  void SetX( int aX )
118  {
119  wxPoint p( aX, GetY() );
120  SetPosition( p );
121  }
122 
123  void SetY( int aY )
124  {
125  wxPoint p( GetX(), aY );
126  SetPosition( p );
127  }
128 
134  virtual bool IsConnected() const
135  {
136  return false;
137  }
138 
142  virtual bool IsOnCopperLayer() const
143  {
144  return IsCopperLayer( GetLayer() );
145  }
146 
150  static wxPoint ZeroOffset;
151 
164  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const;
165 
167 
171  virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
172 
176  virtual LSET GetLayerSet() const { return LSET( m_layer ); }
177  virtual void SetLayerSet( LSET aLayers )
178  {
179  wxFAIL_MSG( "Attempted to SetLayerSet() on a single-layer object." );
180 
181  // Derived classes which support multiple layers must implement this
182  }
183 
192  virtual void SetLayer( PCB_LAYER_ID aLayer )
193  {
194  m_layer = aLayer;
195  }
196 
200  virtual BOARD_ITEM* Duplicate() const
201  {
202  EDA_ITEM* dupe = Clone();
203  const_cast<KIID&>( dupe->m_Uuid ) = KIID();
204 
205  return static_cast<BOARD_ITEM*>( dupe );
206  }
207 
218  virtual void SwapData( BOARD_ITEM* aImage );
219 
229  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
230  {
231  return m_layer == aLayer;
232  }
233 
239  bool IsTrack() const
240  {
241  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
242  }
243 
247  virtual bool IsLocked() const;
248 
252  virtual void SetLocked( bool aLocked )
253  {
254  SetState( LOCKED, aLocked );
255  }
256 
260  void DeleteStructure();
261 
265  static wxString ShowShape( SHAPE_T aShape );
266 
272  virtual void Move( const wxPoint& aMoveVector )
273  {
274  wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
275  GetClass() ) );
276  }
277 
278  void Move( const VECTOR2I& aMoveVector )
279  {
280  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
281  }
282 
289  virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
290 
291  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
292  {
293  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
294  }
295 
302  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight );
303 
304  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
305  {
306  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
307  }
308 
312  virtual BOARD* GetBoard() const;
313 
319  wxString GetLayerName() const;
320 
321  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
322 
335  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
336  PCB_LAYER_ID aLayer, int aClearanceValue,
337  int aError, ERROR_LOC aErrorLoc,
338  bool ignoreLineWidth = false ) const;
339 
340  struct ptr_cmp
341  {
342  bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
343  };
344 
345 protected:
350  virtual wxString layerMaskDescribe() const;
351 
354 };
355 
356 #ifndef SWIG
358 #endif
359 
360 
367 {
368 public:
370  BOARD_ITEM( nullptr, NOT_USED )
371  {}
372 
373  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override
374  {
375  return _( "(Deleted Item)" );
376  }
377 
378  wxString GetClass() const override
379  {
380  return wxT( "DELETED_BOARD_ITEM" );
381  }
382 
383  // pure virtuals:
384  void SetPosition( const wxPoint& ) override {}
385  wxPoint GetPosition() const override { return wxPoint(0, 0); }
386 
388  {
389  static DELETED_BOARD_ITEM* item = nullptr;
390 
391  if( !item )
392  item = new DELETED_BOARD_ITEM();
393 
394  return item;
395  }
396 
397 #if defined(DEBUG)
398  void Show( int , std::ostream& ) const override {}
399 #endif
400 };
401 
402 
403 #endif /* BOARD_ITEM_STRUCT_H */
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:91
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:479
Arcs (with rounded ends)
Bezier Curve.
polygon (not yet used for tracks, but could be in microwave apps)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
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:80
wxString GetClass() const override
Return the class name.
Definition: board_item.h:378
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Rotate this object.
Definition: board_item.cpp:178
wxPoint GetPosition() const override
Definition: board_item.h:385
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:119
usual segment : line with rounded ends
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:127
bool IsTrack() const
Test to see if this object is a track or via (or microvia).
Definition: board_item.h:239
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:252
last value for this list
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:366
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:177
virtual bool IsLocked() const
Definition: board_item.cpp:65
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:150
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)
SHAPE_T
The set of shapes for PCB graphics and tracks and footprint graphics in the .m_Shape member.
Definition: board_item.h:46
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:138
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:373
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:86
PCB_LAYER_ID
A quick note on layer IDs:
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.cpp:184
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:142
LSET is a set of PCB_LAYER_IDs.
int GetY() const
Definition: board_item.h:101
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:229
virtual void Move(const wxPoint &aMoveVector)
Move this object.
Definition: board_item.h:272
Represent a set of closed polygons.
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:387
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:51
static wxString SHAPE_T_asString(SHAPE_T a)
Definition: board_item.h:57
#define LOCKED
Pcbnew: locked from movement and deletion.
void SetY(int aY)
Definition: board_item.h:123
#define _(s)
PCB_GROUP * m_group
Definition: board_item.h:353
virtual wxPoint GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:112
a few functions useful in geometry calculations.
void SetPosition(const wxPoint &) override
Definition: board_item.h:384
An abstract shape on 2D plane.
Definition: shape.h:116
void Move(const VECTOR2I &aMoveVector)
Definition: board_item.h:278
void SetX(int aX)
Definition: board_item.h:117
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
Definition: board_item.h:83
const KIID m_Uuid
Definition: eda_item.h:475
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
EDA_UNITS
Definition: eda_units.h:38
virtual wxString GetClass() const =0
Return the class name.
int GetX() const
Definition: board_item.h:95
Board layer functions and definitions.
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:153
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:352
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
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:168
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:134
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.h:200
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:143
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
segment with non rounded ends
const wxPoint GetCenter() const
Definition: eda_rect.h:104
static wxString ShowShape(SHAPE_T aShape)
Convert the enum #PCB_SHAPE_TYPE_T integer value to a wxString.
Definition: board_item.cpp:36
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: board_item.h:304
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:74
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual bool IsOnCopperLayer() const
Definition: board_item.h:142
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:176
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
Definition: board_item.h:291
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:90