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 <convert_to_biu.h>
36 #include <gr_basic.h>
38 
39 
40 class BOARD;
42 class SHAPE_POLY_SET;
43 class PCB_BASE_FRAME;
44 
45 
52 {
53  S_SEGMENT = 0,
60 };
61 
62 
70 class BOARD_ITEM : public EDA_ITEM
71 {
72 
73 protected:
75 
76  static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
77 
78 public:
79 
80  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
81  EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
82  {
83  }
84 
85  // Do not create a copy constructor & operator=.
86  // The ones generated by the compiler are adequate.
87 
88  virtual const wxPoint GetPosition() const = 0;
89 
98  virtual const wxPoint GetCenter() const { return GetPosition(); }
99 
100  virtual void SetPosition( const wxPoint& aPos ) = 0;
101 
107  virtual bool IsConnected() const
108  {
109  return false;
110  }
111 
115  virtual bool IsOnCopperLayer() const
116  {
117  return IsCopperLayer( GetLayer() );
118  }
119 
124 
126 
131  virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
132 
139  virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
140 
148  virtual void SetLayer( PCB_LAYER_ID aLayer )
149  {
150  // trap any invalid layers, then go find the caller and fix it.
151  // wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
152  m_Layer = aLayer;
153  }
154 
159  virtual void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset = ZeroOffset ) = 0;
160 
166  {
167  EDA_ITEM* dupe = Clone();
168  const_cast<KIID&>( dupe->m_Uuid ) = KIID();
169 
170  return static_cast<BOARD_ITEM*>( dupe );
171  }
172 
180  virtual void SwapData( BOARD_ITEM* aImage );
181 
190  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
191  {
192  return m_Layer == aLayer;
193  }
194 
201  bool IsTrack() const
202  {
203  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
204  }
205 
210  virtual bool IsLocked() const
211  {
212  // only MODULEs & TRACKs can be locked at this time.
213  return false;
214  }
215 
220  virtual void SetLocked( bool aLocked )
221  {
222  // only MODULEs & TRACKs can be locked at this time.
223  }
224 
229  void DeleteStructure();
230 
235  static wxString ShowShape( STROKE_T aShape );
236 
237  // Some geometric transforms, that must be rewritten for derived classes
243  virtual void Move( const wxPoint& aMoveVector )
244  {
245  wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
246  GetClass() ) );
247  }
248 
249  void Move( const VECTOR2I& aMoveVector )
250  {
251  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
252  }
253 
260  virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
261  {
262  wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
263  }
264 
265  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
266  {
267  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
268  }
269 
276  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight )
277  {
278  wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
279  }
280 
281  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
282  {
283  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
284  }
285 
290  virtual BOARD* GetBoard() const;
291 
298  wxString GetLayerName() const;
299 
300  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
301 
313  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
314  int aClearanceValue, int aError = ARC_LOW_DEF, bool ignoreLineWidth = false ) const;
315 };
316 
317 #endif /* BOARD_ITEM_STRUCT_H */
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:183
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError=ARC_LOW_DEF, bool ignoreLineWidth=false) const
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
virtual void SetPosition(const wxPoint &aPos)=0
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &offset=ZeroOffset)=0
Function Print BOARD_ITEMs have their own color information.
polygon (not yet used for tracks, but could be in microwave apps)
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.
usual segment : line with rounded ends
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
static int getNextNumberInSequence(const std::set< int > &aSeq, bool aFillSequenceGaps)
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:65
segment with non rounded ends
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
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.
Arcs (with rounded ends)
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
last value for this list
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
Bezier Curve.
void Move(const VECTOR2I &aMoveVector)
virtual const wxPoint GetPosition() const =0
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
const KIID m_Uuid
Definition: base_struct.h:169
virtual bool IsLocked() const
Function IsLocked.
virtual wxString GetClass() const =0
Function GetClass returns the class name.
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:205
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
virtual const wxPoint GetCenter() const
Function GetCenter()
virtual bool IsConnected() const
Function IsConnected() Returns information if the object is derived from BOARD_CONNECTED_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)
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.
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 "layer mask", which is a bitmap of all layers on which the TRACK segme...
BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212