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 
168  virtual void SwapData( BOARD_ITEM* aImage );
169 
178  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
179  {
180  return m_Layer == aLayer;
181  }
182 
189  bool IsTrack() const
190  {
191  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
192  }
193 
198  virtual bool IsLocked() const
199  {
200  // only MODULEs & TRACKs can be locked at this time.
201  return false;
202  }
203 
208  virtual void SetLocked( bool aLocked )
209  {
210  // only MODULEs & TRACKs can be locked at this time.
211  }
212 
217  void DeleteStructure();
218 
223  static wxString ShowShape( STROKE_T aShape );
224 
225  // Some geometric transforms, that must be rewritten for derived classes
231  virtual void Move( const wxPoint& aMoveVector )
232  {
233  wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
234  GetClass() ) );
235  }
236 
237  void Move( const VECTOR2I& aMoveVector )
238  {
239  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
240  }
241 
248  virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
249  {
250  wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
251  }
252 
253  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
254  {
255  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
256  }
257 
264  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight )
265  {
266  wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
267  }
268 
269  void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
270  {
271  Flip( wxPoint( aCentre.x, aCentre.y ), aFlipLeftRight );
272  }
273 
278  virtual BOARD* GetBoard() const;
279 
286  wxString GetLayerName() const;
287 
288  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
289 
301  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
302  int aClearanceValue, int aError = ARC_LOW_DEF, bool ignoreLineWidth = false ) const;
303 };
304 
305 #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:177
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.
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.
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)
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:160
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
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...
void Rotate(const VECTOR2I &aRotCentre, double aAngle)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207