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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
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 <gr_basic.h>
37 
39 #define FMT_IU BOARD_ITEM::FormatInternalUnits
40 #define FMT_ANGLE BOARD_ITEM::FormatAngle
41 
42 class BOARD;
44 class EDA_DRAW_PANEL;
45 
46 
53 {
54  S_SEGMENT = 0,
61 };
62 
63 
71 class BOARD_ITEM : public EDA_ITEM
72 {
73  // These are made private here so they may not be used.
74  // Instead everything derived from BOARD_ITEM is handled via DLIST<>'s
75  // use of DHEAD's member functions.
76  void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
77  void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
78 
79 protected:
81 
82  static int getTrailingInt( wxString aStr );
83  static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
84 
85 public:
86 
87  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
88  EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
89  {
90  }
91 
92  // Do not create a copy constructor & operator=.
93  // The ones generated by the compiler are adequate.
94 
95  virtual const wxPoint& GetPosition() const = 0;
96 
105  virtual const wxPoint GetCenter() const { return GetPosition(); }
106 
107  virtual void SetPosition( const wxPoint& aPos ) = 0;
108 
114  virtual bool IsConnected() const
115  {
116  return false;
117  }
118 
123 
124  BOARD_ITEM* Next() const { return static_cast<BOARD_ITEM*>( Pnext ); }
125  BOARD_ITEM* Back() const { return static_cast<BOARD_ITEM*>( Pback ); }
127 
132  PCB_LAYER_ID GetLayer() const { return m_Layer; }
133 
140  virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
141 
149  virtual void SetLayer( PCB_LAYER_ID aLayer )
150  {
151  // trap any invalid layers, then go find the caller and fix it.
152  // wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
153  m_Layer = aLayer;
154  }
155 
160  virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
161  GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0;
162 
172  void SwapData( BOARD_ITEM* aImage );
173 
182  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
183  {
184  return m_Layer == aLayer;
185  }
186 
193  bool IsTrack() const
194  {
195  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
196  }
197 
202  virtual bool IsLocked() const
203  {
204  // only MODULEs & TRACKs can be locked at this time.
205  return false;
206  }
207 
212  virtual void SetLocked( bool aLocked )
213  {
214  // only MODULEs & TRACKs can be locked at this time.
215  }
216 
222  virtual void UnLink();
223 
228  void DeleteStructure();
229 
234  static wxString ShowShape( STROKE_T aShape );
235 
236  // Some geometric transforms, that must be rewritten for derived classes
242  virtual void Move( const wxPoint& aMoveVector )
243  {
244  wxMessageBox( wxT( "virtual BOARD_ITEM::Move used, should not occur" ), GetClass() );
245  }
246 
253  virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
254  {
255  wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
256  }
257 
263  virtual void Flip( const wxPoint& aCentre )
264  {
265  wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
266  }
267 
272  virtual BOARD* GetBoard() const;
273 
280  wxString GetLayerName() const;
281 
282  virtual bool HitTest( const wxPoint& aPosition ) const override
283  {
284  return EDA_ITEM::HitTest( aPosition );
285  }
286 
297  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0) const
298  {
299  return false; // derived classes should override this function
300  }
301 
302 
312  static std::string FormatInternalUnits( int aValue );
313 
323  static std::string FormatAngle( double aAngle );
324 
325  static std::string FormatInternalUnits( const wxPoint& aPoint );
326 
327  static std::string FormatInternalUnits( const wxSize& aSize );
328 
330  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
331 };
332 
333 #endif /* BOARD_ITEM_STRUCT_H */
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
BOARD_ITEM_CONTAINER * GetParent() const
static wxString ShowShape(STROKE_T aShape)
Function ShowShape converts the enum STROKE_T integer value to a wxString.
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:165
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:168
virtual void SetPosition(const wxPoint &aPos)=0
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
polygon (not yet used for tracks, but could be in microwave apps)
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
virtual const wxPoint & GetPosition() const =0
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one...
usual segment : line with rounded ends
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
virtual void UnLink()
Function UnLink detaches this object from its owner.
virtual void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)=0
Function Draw BOARD_ITEMs have their own color information.
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
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:90
static wxPoint ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
static std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from board internal units to a string appropriate for wr...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
virtual const wxPoint GetCenter() const
Function GetCenter()
BOARD_ITEM * Next() const
PCB_LAYER_ID m_Layer
void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: undo_redo.cpp:577
segment with non rounded ends
static int getTrailingInt(wxString aStr)
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
static std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file...
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
void SetNext(EDA_ITEM *aNext)
Arcs (with rounded ends)
last value for this list
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
virtual bool HitTest(const wxPoint &aPosition) const
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: base_struct.h:288
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
Bezier Curve.
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype)
virtual void Flip(const wxPoint &aCentre)
Function Flip Flip this object, i.e.
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
virtual wxString GetClass() const =0
Function GetClass returns the class name.
Board layer functions and definitions.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
virtual bool IsLocked() const
Function IsLocked.
virtual bool IsConnected() const
Function IsConnected() Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Class EDA_RECT handles the component boundary box.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Basic classes for most KiCad items.
bool IsTrack() const
Function IsTrack tests to see if this object is a track or via (or microvia).
virtual bool HitTest(const EDA_RECT &aRect, bool aContained=true, int aAccuracy=0) const
Function HitTest tests if the aRect intersects or contains this object (depending on aContained)...
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:164
BOARD_ITEM * Back() const
void SetBack(EDA_ITEM *aBack)