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 #include <wx/msgdlg.h>
37 
38 class BOARD;
40 class SHAPE_POLY_SET;
41 class PCB_BASE_FRAME;
42 class SHAPE;
43 class PCB_GROUP;
44 
49 {
50  S_SEGMENT = 0,
57 };
58 
59 static inline wxString PCB_SHAPE_TYPE_T_asString( PCB_SHAPE_TYPE_T a )
60 {
61  switch( a )
62  {
63  case S_SEGMENT: return "S_SEGMENT";
64  case S_RECT: return "S_RECT";
65  case S_ARC: return "S_ARC";
66  case S_CIRCLE: return "S_CIRCLE";
67  case S_POLYGON: return "S_POLYGON";
68  case S_CURVE: return "S_CURVE";
69  case S_LAST: return "S_LAST"; // Synthetic value, but if we come across it we're
70  // going to want to know.
71  }
72 
73  return wxEmptyString; // Just to quiet GCC.
74 };
75 
76 
82 class BOARD_ITEM : public EDA_ITEM
83 {
84 public:
85  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
86  EDA_ITEM( aParent, idtype ),
87  m_layer( F_Cu ),
88  m_group( nullptr )
89  {
90  }
91 
92  void SetParentGroup( PCB_GROUP* aGroup ) { m_group = aGroup; }
93  PCB_GROUP* GetParentGroup() const { return m_group; }
94 
95  // Do not create a copy constructor & operator=.
96  // The ones generated by the compiler are adequate.
97  int GetX() const
98  {
99  wxPoint p = GetPosition();
100  return p.x;
101  }
102 
103  int GetY() const
104  {
105  wxPoint p = GetPosition();
106  return p.y;
107  }
108 
114  virtual wxPoint GetCenter() const
115  {
116  return GetBoundingBox().GetCenter();
117  }
118 
119  void SetX( int aX )
120  {
121  wxPoint p( aX, GetY() );
122  SetPosition( p );
123  }
124 
125  void SetY( int aY )
126  {
127  wxPoint p( GetX(), aY );
128  SetPosition( p );
129  }
130 
136  virtual bool IsConnected() const
137  {
138  return false;
139  }
140 
144  virtual bool IsOnCopperLayer() const
145  {
146  return IsCopperLayer( GetLayer() );
147  }
148 
152  static wxPoint ZeroOffset;
153 
166  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const;
167 
169 
173  virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
174 
178  virtual LSET GetLayerSet() const { return LSET( m_layer ); }
179  virtual void SetLayerSet( LSET aLayers )
180  {
181  wxFAIL_MSG( "Attempted to SetLayerSet() on a single-layer object." );
182 
183  // Derived classes which support multiple layers must implement this
184  }
185 
194  virtual void SetLayer( PCB_LAYER_ID aLayer )
195  {
196  m_layer = aLayer;
197  }
198 
202  virtual BOARD_ITEM* Duplicate() const
203  {
204  EDA_ITEM* dupe = Clone();
205  const_cast<KIID&>( dupe->m_Uuid ) = KIID();
206 
207  return static_cast<BOARD_ITEM*>( dupe );
208  }
209 
220  virtual void SwapData( BOARD_ITEM* aImage );
221 
231  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
232  {
233  return m_layer == aLayer;
234  }
235 
241  bool IsTrack() const
242  {
243  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
244  }
245 
249  virtual bool IsLocked() const
250  {
251  return GetState( LOCKED );
252  }
253 
257  virtual void SetLocked( bool aLocked )
258  {
259  SetState( LOCKED, aLocked );
260  }
261 
265  void DeleteStructure();
266 
270  static wxString ShowShape( PCB_SHAPE_TYPE_T aShape );
271 
277  virtual void Move( const wxPoint& aMoveVector )
278  {
279  wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
280  GetClass() ) );
281  }
282 
283  void Move( const VECTOR2I& aMoveVector )
284  {
285  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
286  }
287 
294  virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
295  {
296  wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
297  }
298 
299  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
300  {
301  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
302  }
303 
310  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight )
311  {
312  wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
313  }
314 
315  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
316  {
317  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
318  }
319 
323  virtual BOARD* GetBoard() const;
324 
330  wxString GetLayerName() const;
331 
332  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
333 
346  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
347  PCB_LAYER_ID aLayer, int aClearanceValue,
348  int aError, ERROR_LOC aErrorLoc,
349  bool ignoreLineWidth = false ) const;
350 
351  struct ptr_cmp
352  {
353  bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
354  };
355 
356 protected:
361  virtual wxString layerMaskDescribe() const;
362 
365 };
366 
367 #ifndef SWIG
369 #endif
370 
371 
378 {
379 public:
381  BOARD_ITEM( nullptr, NOT_USED )
382  {}
383 
384  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override
385  {
386  return _( "(Deleted Item)" );
387  }
388 
389  wxString GetClass() const override
390  {
391  return wxT( "DELETED_BOARD_ITEM" );
392  }
393 
394  // pure virtuals:
395  void SetPosition( const wxPoint& ) override {}
396  wxPoint GetPosition() const override { return wxPoint(0, 0); }
397 
399  {
400  static DELETED_BOARD_ITEM* item = nullptr;
401 
402  if( !item )
403  item = new DELETED_BOARD_ITEM();
404 
405  return item;
406  }
407 
408 #if defined(DEBUG)
409  void Show( int , std::ostream& ) const override {}
410 #endif
411 };
412 
413 
414 #endif /* BOARD_ITEM_STRUCT_H */
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:93
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:527
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:301
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
wxString GetClass() const override
Return the class name.
Definition: board_item.h:389
wxPoint GetPosition() const override
Definition: board_item.h:396
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Definition: pcb_group.h:50
the 3d code uses this value
Definition: typeinfo.h:79
polygon (not yet used for tracks, but could be in microwave apps)
Definition: board_item.h:54
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:105
void DeleteStructure()
Delete this object after removing from its parent if it has one.
Definition: board_item.cpp:113
bool IsTrack() const
Test to see if this object is a track or via (or microvia).
Definition: board_item.h:241
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight)
Flip this object, i.e.
Definition: board_item.h:310
static wxString ShowShape(PCB_SHAPE_TYPE_T aShape)
Convert the enum PCB_SHAPE_TYPE_T integer value to a wxString.
Definition: board_item.cpp:31
usual segment : line with rounded ends
Definition: board_item.h:50
Arcs (with rounded ends)
Definition: board_item.h:52
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:257
virtual wxPoint GetPosition() const
Definition: eda_item.h:300
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: board_item.h:377
virtual void SetLayerSet(LSET aLayers)
Definition: board_item.h:179
segment with non rounded ends
Definition: board_item.h:51
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:152
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:97
class 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:124
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:384
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:72
PCB_LAYER_ID
A quick note on layer IDs:
PCB_SHAPE_TYPE_T
The set of shapes for PCB graphics and tracks and footprint graphics in the .m_Shape member.
Definition: board_item.h:48
LSET is a set of PCB_LAYER_IDs.
int GetY() const
Definition: board_item.h:103
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:231
last value for this list
Definition: board_item.h:56
virtual void Move(const wxPoint &aMoveVector)
Move this object.
Definition: board_item.h:277
SHAPE_POLY_SET.
static DELETED_BOARD_ITEM * GetInstance()
Definition: board_item.h:398
static wxString PCB_SHAPE_TYPE_T_asString(PCB_SHAPE_TYPE_T a)
Definition: board_item.h:59
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
void SetY(int aY)
Definition: board_item.h:125
PCB_GROUP * m_group
Definition: board_item.h:364
virtual wxPoint GetCenter() const
This defaults to the center of the bounding box if not overridden.
Definition: board_item.h:114
a few functions useful in geometry calculations.
void SetPosition(const wxPoint &) override
Definition: board_item.h:395
SHAPE.
Definition: shape.h:123
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Rotate this object.
Definition: board_item.h:294
void Move(const VECTOR2I &aMoveVector)
Definition: board_item.h:283
void SetX(int aX)
Definition: board_item.h:119
#define LOCKED
Pcbnew: locked from movement and deletion.
Definition: eda_item.h:120
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
Definition: board_item.h:85
const KIID m_Uuid
Definition: eda_item.h:523
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 bool IsLocked() const
Definition: board_item.h:249
virtual wxString GetClass() const =0
Return the class name.
int GetX() const
Definition: board_item.h:97
void SetState(int type, int state)
Definition: eda_item.h:190
Board layer functions and definitions.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:189
#define _(s)
Definition: 3d_actions.cpp:33
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
Definition: board_item.cpp:138
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
PCB_LAYER_ID m_layer
Definition: board_item.h:363
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:153
ring
Definition: board_item.h:53
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:136
virtual BOARD_ITEM * Duplicate() const
Create a copy of a of this BOARD_ITEM.
Definition: board_item.h:202
class 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:129
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:89
const wxPoint GetCenter() const
Definition: eda_rect.h:109
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
Definition: board_item.h:315
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:60
Bezier Curve.
Definition: board_item.h:55
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
int GetState(int type) const
Definition: eda_item.h:185
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual bool IsOnCopperLayer() const
Definition: board_item.h:144
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:178
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
Definition: board_item.h:299
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:92