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 <gr_basic.h>
37 
38 
39 class BOARD;
41 class EDA_DRAW_PANEL;
42 class SHAPE_POLY_SET;
43 
50 {
51  S_SEGMENT = 0,
58 };
59 
60 
68 class BOARD_ITEM : public EDA_ITEM
69 {
70 
71 protected:
73 
74  static int getTrailingInt( const wxString& aStr );
75  static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
76 
77 public:
78 
79  BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
80  EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
81  {
82  }
83 
84  // Do not create a copy constructor & operator=.
85  // The ones generated by the compiler are adequate.
86 
87  virtual const wxPoint GetPosition() const = 0;
88 
97  virtual const wxPoint GetCenter() const { return GetPosition(); }
98 
99  virtual void SetPosition( const wxPoint& aPos ) = 0;
100 
106  virtual bool IsConnected() const
107  {
108  return false;
109  }
110 
115 
116  BOARD_ITEM* Next() const { return static_cast<BOARD_ITEM*>( Pnext ); }
117  BOARD_ITEM* Back() const { return static_cast<BOARD_ITEM*>( Pback ); }
119 
124  virtual PCB_LAYER_ID GetLayer() const { return m_Layer; }
125 
132  virtual LSET GetLayerSet() const { return LSET( m_Layer ); }
133 
141  virtual void SetLayer( PCB_LAYER_ID aLayer )
142  {
143  // trap any invalid layers, then go find the caller and fix it.
144  // wxASSERT( unsigned( aLayer ) < unsigned( NB_PCB_LAYERS ) );
145  m_Layer = aLayer;
146  }
147 
152  virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
153  GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ) = 0;
154 
164  virtual void SwapData( BOARD_ITEM* aImage );
165 
174  virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
175  {
176  return m_Layer == aLayer;
177  }
178 
185  bool IsTrack() const
186  {
187  return ( Type() == PCB_TRACE_T ) || ( Type() == PCB_VIA_T );
188  }
189 
194  virtual bool IsLocked() const
195  {
196  // only MODULEs & TRACKs can be locked at this time.
197  return false;
198  }
199 
204  virtual void SetLocked( bool aLocked )
205  {
206  // only MODULEs & TRACKs can be locked at this time.
207  }
208 
214  virtual void UnLink();
215 
220  void DeleteStructure();
221 
226  static wxString ShowShape( STROKE_T aShape );
227 
228  // Some geometric transforms, that must be rewritten for derived classes
234  virtual void Move( const wxPoint& aMoveVector )
235  {
236  wxFAIL_MSG( wxString::Format( wxT( "virtual BOARD_ITEM::Move called for %s" ),
237  GetClass() ) );
238  }
239 
240  void Move( const VECTOR2I& aMoveVector )
241  {
242  Move( wxPoint( aMoveVector.x, aMoveVector.y ) );
243  }
244 
251  virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
252  {
253  wxMessageBox( wxT( "virtual BOARD_ITEM::Rotate used, should not occur" ), GetClass() );
254  }
255 
256  void Rotate( const VECTOR2I& aRotCentre, double aAngle )
257  {
258  Rotate( wxPoint( aRotCentre.x, aRotCentre.y ), aAngle );
259  }
260 
266  virtual void Flip( const wxPoint& aCentre )
267  {
268  wxMessageBox( wxT( "virtual BOARD_ITEM::Flip used, should not occur" ), GetClass() );
269  }
270 
271  void Flip( const VECTOR2I& aCentre )
272  {
273  Flip( wxPoint( aCentre.x, aCentre.y ) );
274  }
275 
280  virtual BOARD* GetBoard() const;
281 
288  wxString GetLayerName() const;
289 
290  virtual bool HitTest( const wxPoint& aPosition ) const override
291  {
292  return EDA_ITEM::HitTest( aPosition );
293  }
294 
305  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0) const
306  {
307  return false; // derived classes should override this function
308  }
309 
310 
320  static std::string FormatInternalUnits( int aValue );
321 
331  static std::string FormatAngle( double aAngle );
332 
333  static std::string FormatInternalUnits( const wxPoint& aPoint );
334 
335  static std::string FormatInternalUnits( const VECTOR2I& aPoint );
336 
337  static std::string FormatInternalUnits( const wxSize& aSize );
338 
339  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
340 
341  virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
342  int aClearanceValue,
343  int aCircleToSegmentsCount,
344  double aCorrectionFactor ) const;
345 };
346 
347 #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...
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
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 UnLink()ing it from its owner if it has one...
usual segment : line with rounded ends
virtual void SetLocked(bool aLocked)
Function SetLocked modifies &#39;lock&#39; status for of the item.
virtual void UnLink()
Function UnLink detaches this object from its owner.
virtual void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const
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:78
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:95
virtual const wxPoint GetCenter() const
Function GetCenter()
BOARD_ITEM * Next() const
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:
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:37
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
Class SHAPE_POLY_SET.
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.
void Move(const VECTOR2I &aMoveVector)
virtual const wxPoint GetPosition() const =0
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...
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
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
virtual bool IsLocked() const
Function IsLocked.
static int getTrailingInt(const wxString &aStr)
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.
Definition: eda_rect.h:44
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:96
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
void Flip(const VECTOR2I &aCentre)
BOARD_ITEM * Back() const
void Rotate(const VECTOR2I &aRotCentre, double aAngle)