KiCad PCB EDA Suite
class_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-2016 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 
30 #ifndef BOARD_ITEM_STRUCT_H
31 #define BOARD_ITEM_STRUCT_H
32 
33 
34 #include <base_struct.h>
35 #include <common.h>
36 #include <convert_to_biu.h>
37 #include <gr_basic.h>
39 
40 
41 class BOARD;
43 class SHAPE_POLY_SET;
44 class PCB_BASE_FRAME;
45 class SHAPE;
46 
53 {
54  S_SEGMENT = 0,
61 };
62 
63 static inline wxString STROKE_T_asString( STROKE_T a )
64 {
65  switch( a )
66  {
67  case S_SEGMENT: return "S_SEGMENT";
68  case S_RECT: return "S_RECT";
69  case S_ARC: return "S_ARC";
70  case S_CIRCLE: return "S_CIRCLE";
71  case S_POLYGON: return "S_POLYGON";
72  case S_CURVE: return "S_CURVE";
73  case S_LAST: return "S_LAST"; // Synthetic value, but if we come across it we're
74  // going to want to know.
75  }
76 
77  return wxEmptyString; // Just to quiet GCC.
78 };
79 
80 
88 class BOARD_ITEM : public EDA_ITEM
89 {
90 protected:
93 
94 public:
95  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype )
96  : EDA_ITEM( aParent, idtype ),
97  m_Layer( F_Cu ),
98  m_groupUuid( 0 )
99  {
100  }
101 
107  void SetGroup( const KIID& aGroup ) { m_groupUuid = aGroup; }
108 
114  const KIID& GetGroup() const { return m_groupUuid; }
115 
121  bool IsInGroup() { return m_groupUuid != niluuid; }
122 
123  // Do not create a copy constructor & operator=.
124  // The ones generated by the compiler are adequate.
125  int GetX() const
126  {
127  wxPoint p = GetPosition();
128  return p.x;
129  }
130 
131  int GetY() const
132  {
133  wxPoint p = GetPosition();
134  return p.y;
135  }
136 
145  virtual wxPoint GetCenter() const { return GetPosition(); }
146 
147  void SetX( int aX )
148  {
149  wxPoint p( aX, GetY() );
150  SetPosition( p );
151  }
152 
153  void SetY( int aY )
154  {
155  wxPoint p( GetX(), aY );
156  SetPosition( p );
157  }
158 
164  virtual bool IsConnected() const
165  {
166  return false;
167  }
168 
172  virtual bool IsOnCopperLayer() const
173  {
174  return IsCopperLayer( GetLayer() );
175  }
176 
181 
195  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const;
196 
198 
203  virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
204 
209  virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
210  virtual void SetLayerSet( LSET aLayers )
211  {
212  wxFAIL_MSG( "Attempted to SetLayerSet() on a single-layer object." );
213 
214  // Derived classes which support multiple layers must implement this
215  }
216 
224  virtual void SetLayer( PCB_LAYER_ID aLayer )
225  {
226  m_Layer = aLayer;
227  }
228 
233  virtual BOARD_ITEM* Duplicate() const
234  {
235  EDA_ITEM* dupe = Clone();
236  const_cast<KIID&>( dupe->m_Uuid ) = KIID();
237 
238  return static_cast<BOARD_ITEM*>( dupe );
239  }
240 
248  virtual void SwapData( BOARD_ITEM* aImage );
249 
258  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
259  {
260  return m_Layer == aLayer;
261  }
262 
269  bool IsTrack() const
270  {
271  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
272  }
273 
278  virtual bool IsLocked() const
279  {
280  // only MODULEs & TRACKs can be locked at this time.
281  return false;
282  }
283 
288  virtual void SetLocked( bool aLocked )
289  {
290  // only MODULEs & TRACKs can be locked at this time.
291  }
292 
297  void DeleteStructure();
298 
303  static wxString ShowShape( STROKE_T aShape );
304 
305  // Some geometric transforms, that must be rewritten for derived classes
311  virtual void Move( const wxPoint& aMoveVector )
312  {
313  wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
314  GetClass() ) );
315  }
316 
317  void Move( const VECTOR2I& aMoveVector )
318  {
319  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
320  }
321 
328  virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
329  {
330  wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
331  }
332 
333  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
334  {
335  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
336  }
337 
344  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight )
345  {
346  wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
347  }
348 
349  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
350  {
351  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
352  }
353 
358  virtual BOARD* GetBoard() const;
359 
366  wxString GetLayerName() const;
367 
368  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
369 
381  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
382  PCB_LAYER_ID aLayer,
383  int aClearanceValue,
384  int aError = ARC_LOW_DEF,
385  bool ignoreLineWidth = false ) const;
386 
387  struct ptr_cmp
388  {
389  bool operator() ( const BOARD_ITEM* a, const BOARD_ITEM* b ) const;
390  };
391 
392 protected:
398  virtual wxString LayerMaskDescribe() const;
399 };
400 
401 #ifndef SWIG
403 #endif
404 
405 
411 {
412 public:
414  BOARD_ITEM( nullptr, NOT_USED )
415  {}
416 
417  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override
418  {
419  return _( "(Deleted Item)" );
420  }
421 
422  wxString GetClass() const override
423  {
424  return wxT( "DELETED_BOARD_ITEM" );
425  }
426 
427  // pure virtuals:
428  void SetPosition( const wxPoint& ) override {}
429 
430  wxPoint GetPosition() const override {
431  return wxPoint(0, 0);
432  }
433 
435  {
436  static DELETED_BOARD_ITEM* item = nullptr;
437 
438  if( !item )
439  item = new DELETED_BOARD_ITEM();
440 
441  return item;
442  }
443 
444 #if defined(DEBUG)
445  void Show( int , std::ostream& ) const override {}
446 #endif
447 };
448 
449 
450 #endif /* BOARD_ITEM_STRUCT_H */
EDA_UNITS
Definition: common.h:198
static wxString ShowShape(STROKE_T aShape)
Function ShowShape converts the enum STROKE_T integer value to a wxString.
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:174
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
virtual void SetPosition(const wxPoint &aPos)
Definition: base_struct.h:338
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
wxString GetClass() const override
Function GetClass returns the class name.
wxPoint GetPosition() const override
the 3d code uses this value
Definition: typeinfo.h:80
polygon (not yet used for tracks, but could be in microwave apps)
bool IsInGroup()
Test if this item is inside a group.
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
void DeleteStructure()
Function DeleteStructure deletes this object after removing from its parent if it has one.
bool IsTrack() const
Function IsTrack tests to see if this object is a track or via (or microvia).
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight)
Function Flip Flip this object, i.e.
virtual wxString LayerMaskDescribe() const
Helper function Return a string (to be shown to the user) describing a layer mask.
usual segment : line with rounded ends
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
virtual wxPoint GetPosition() const
Definition: base_struct.h:337
A singleton item of this class is returned for a weak reference that no longer exists.
virtual void SetLayerSet(LSET aLayers)
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
static wxPoint ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
PCB_LAYER_ID m_Layer
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: common.h:68
segment with non rounded ends
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
int GetY() const
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
SHAPE_POLY_SET.
void SetGroup(const KIID &aGroup)
Set the group that this item belongs to.
static DELETED_BOARD_ITEM * GetInstance()
Arcs (with rounded ends)
KIID niluuid(0)
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
last value for this list
void SetY(int aY)
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
virtual wxPoint GetCenter() const
Function GetCenter()
void SetPosition(const wxPoint &) override
SHAPE.
Definition: shape.h:120
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
Bezier Curve.
void Move(const VECTOR2I &aMoveVector)
void SetX(int aX)
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
const KIID m_Uuid
Definition: base_struct.h:162
static wxString STROKE_T_asString(STROKE_T a)
virtual bool IsLocked() const
Function IsLocked.
virtual wxString GetClass() const =0
Function GetClass returns the class name.
int GetX() const
Board layer functions and definitions.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:178
#define _(s)
Definition: 3d_actions.cpp:33
bool operator()(const BOARD_ITEM *a, const BOARD_ITEM *b) const
const KIID & GetGroup() const
Get the group this item belongs to.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
The common library.
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Function GetEffectiveShape Some pad shapes can be complex (rounded/chamfered rectangle),...
virtual bool IsConnected() const
Function IsConnected() Returns information if the object is derived from BOARD_CONNECTED_ITEM.
virtual BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD_ITEM_CONTAINER * GetParent() const
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight)
DECLARE_ENUM_TO_WXANY(PCB_LAYER_ID)
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError=ARC_LOW_DEF, bool ignoreLineWidth=false) const
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual bool IsOnCopperLayer() const
virtual LSET GetLayerSet() const
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193