KiCad PCB EDA Suite
class_track.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-2019 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 CLASS_TRACK_H
31 #define CLASS_TRACK_H
32 
33 
34 #include <board_connected_item.h>
35 #include <class_board_item.h>
36 #include <convert_to_biu.h>
37 #include <pcb_display_options.h>
38 #include <pcbnew.h>
39 
40 #include <geometry/seg.h>
41 
42 #include <trigo.h>
43 
44 
45 class TRACK;
46 class VIA;
47 class D_PAD;
48 class MSG_PANEL_ITEM;
49 class SHAPE_POLY_SET;
50 
51 
52 // Flag used in locate routines (from which endpoint work)
53 enum ENDPOINT_T {
56 };
57 
58 // Via types
59 // Note that this enum must be synchronized to GAL_LAYER_ID
60 enum class VIATYPE
61 {
62  THROUGH = 3, /* Always a through hole via */
63  BLIND_BURIED = 2, /* this via can be on internal layers */
64  MICROVIA = 1, /* this via which connect from an external layer
65  * to the near neighbor internal layer */
66  NOT_DEFINED = 0 /* not yet used */
67 };
68 
69 #define UNDEFINED_DRILL_DIAMETER -1 //< Undefined via drill diameter.
70 
71 #define MIN_VIA_DRAW_SIZE 4
72 
73 // Used for tracks and vias for algorithmic safety, not to enforce constraints
74 #define GEOMETRY_MIN_SIZE ( int )( 0.001 * IU_PER_MM )
75 
76 
78 {
79 public:
80  static inline bool ClassOf( const EDA_ITEM* aItem )
81  {
82  return aItem && PCB_TRACE_T == aItem->Type();
83  }
84 
85  TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
86 
87  // Do not create a copy constructor. The one generated by the compiler is adequate.
88 
89  void Move( const wxPoint& aMoveVector ) override
90  {
91  m_Start += aMoveVector;
92  m_End += aMoveVector;
93  }
94 
95  void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
96 
97  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
98 
99  void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; }
100  const wxPoint GetPosition() const override { return m_Start; }
101 
102  void SetWidth( int aWidth ) { m_Width = aWidth; }
103  int GetWidth() const { return m_Width; }
104 
105  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
106  const wxPoint& GetEnd() const { return m_End; }
107 
108  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
109  const wxPoint& GetStart() const { return m_Start; }
110 
111 
113  const wxPoint& GetEndPoint( ENDPOINT_T aEndPoint ) const
114  {
115  if( aEndPoint == ENDPOINT_START )
116  return m_Start;
117  else
118  return m_End;
119  }
120 
121  // Virtual function
122  const EDA_RECT GetBoundingBox() const override;
123 
124  bool IsLocked() const override
125  {
126  return GetState( TRACK_LOCKED );
127  }
128 
129  void SetLocked( bool aLocked ) override
130  {
131  return SetState( TRACK_LOCKED, aLocked );
132  }
133 
139  double GetLength() const
140  {
141  return GetLineLength( m_Start, m_End );
142  }
143 
144  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset = ZeroOffset ) override;
145 
157  void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue,
158  int aError = ARC_HIGH_DEF, bool ignoreLineWidth = false ) const override;
166  STATUS_FLAGS IsPointOnEnds( const wxPoint& point, int min_dist = 0 ) const;
167 
172  bool IsNull() const
173  {
174  return ( Type() == PCB_VIA_T ) || ( m_Start == m_End );
175  }
176 
177  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
178 
179  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
180 
181  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
182  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
183 
184  bool ApproxCollinear( const TRACK& aTrack )
185  {
186  SEG a( m_Start, m_End );
187  SEG b( aTrack.GetStart(), aTrack.GetEnd() );
188  return a.ApproxCollinear( b );
189  }
190 
191  wxString GetClass() const override
192  {
193  return wxT( "TRACK" );
194  }
195 
205  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const override;
206 
207  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
208 
209  BITMAP_DEF GetMenuImage() const override;
210 
211  virtual EDA_ITEM* Clone() const override;
212 
213  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
214 
215  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
216 
217  const BOX2I ViewBBox() const override;
218 
219  virtual void SwapData( BOARD_ITEM* aImage ) override;
220 
224  bool IsOnCopperLayer() const override
225  {
226  return true;
227  }
228 
229 #if defined (DEBUG)
230  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
231 
237  static wxString ShowState( int stateBits );
238 
239 #endif
240 
241 protected:
247  virtual void GetMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList );
248 
249 
250  void GetMsgPanelInfoBase_Common( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList );
251 
252 
253  int m_Width;
256 
257 };
258 
259 
260 class VIA : public TRACK
261 {
262 public:
263  VIA( BOARD_ITEM* aParent );
264 
265  static inline bool ClassOf( const EDA_ITEM *aItem )
266  {
267  return aItem && PCB_VIA_T == aItem->Type();
268  }
269 
270  // Do not create a copy constructor. The one generated by the compiler is adequate.
271 
272  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset = ZeroOffset ) override;
273 
274  bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
275 
276  virtual LSET GetLayerSet() const override;
277 
285  void SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer );
286 
287  void SetBottomLayer( PCB_LAYER_ID aLayer );
288  void SetTopLayer( PCB_LAYER_ID aLayer );
289 
297  void LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const;
298 
299  PCB_LAYER_ID TopLayer() const;
300  PCB_LAYER_ID BottomLayer() const;
301 
307  void SanitizeLayers();
308 
309  const wxPoint GetPosition() const override { return m_Start; }
310  void SetPosition( const wxPoint& aPoint ) override { m_Start = aPoint; m_End = aPoint; }
311 
312  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
313  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
314 
315  wxString GetClass() const override
316  {
317  return wxT( "VIA" );
318  }
319 
320  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
321 
322  BITMAP_DEF GetMenuImage() const override;
323 
324  EDA_ITEM* Clone() const override;
325 
326  void ViewGetLayers( int aLayers[], int& aCount ) const override;
327 
328  unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
329 
330  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
331 
332 #if defined (DEBUG)
333  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
334 #endif
335 
337  {
338  return m_ViaType;
339  }
340 
341  void SetViaType( VIATYPE aViaType )
342  {
343  m_ViaType = aViaType;
344  }
345 
351  void SetDrill( int aDrill ) { m_Drill = aDrill; }
352 
358  int GetDrill() const { return m_Drill; }
359 
366  int GetDrillValue() const;
367 
373 
378  bool IsDrillDefault() const { return m_Drill <= 0; }
379 
380  virtual void SwapData( BOARD_ITEM* aImage ) override;
381 
382 protected:
383  void GetMsgPanelInfoBase( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
384 
385 private:
388 
389  VIATYPE m_ViaType; // Type of via
390 
391  int m_Drill; // for vias: via drill (- 1 for default value)
392 };
393 
394 
395 #endif // CLASS_TRACK_H
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:124
EDA_UNITS
Definition: common.h:72
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
VIATYPE m_ViaType
Definition: class_track.h:389
wxPoint m_Start
Line start point.
Definition: class_track.h:254
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Function GetLineLength returns the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:202
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
static bool ClassOf(const EDA_ITEM *aItem)
Definition: class_track.h:80
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
bool IsOnCopperLayer() const override
Definition: class_track.h:224
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:310
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:105
const wxPoint & GetStart() const
Definition: class_track.h:109
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
void GetMsgPanelInfo(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
bool IsDrillDefault() const
Function IsDrillDefault.
Definition: class_track.h:378
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError=ARC_HIGH_DEF, bool ignoreLineWidth=false) const override
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_track.cpp:69
void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &aOffset=ZeroOffset) override
Function Print BOARD_ITEMs have their own color information.
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
Definition: class_track.h:89
VIA(BOARD_ITEM *aParent)
Definition: class_track.cpp:75
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
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
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:139
int m_Width
Thickness of track, or via diameter.
Definition: class_track.h:253
void SetWidth(int aWidth)
Definition: class_track.h:102
virtual unsigned int ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:108
void SetLocked(bool aLocked) override
Function SetLocked modifies 'lock' status for of the item.
Definition: class_track.h:129
static bool ClassOf(const EDA_ITEM *aItem)
Definition: class_track.h:265
PCB_LAYER_ID
A quick note on layer IDs:
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
LSET is a set of PCB_LAYER_IDs.
#define NULL
const wxPoint GetPosition() const override
Definition: class_track.h:100
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
virtual void GetMsgPanelInfoBase(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfoBase Display info about the track segment only, and does not calculate the fu...
SHAPE_POLY_SET.
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:358
wxPoint m_End
Line end point.
Definition: class_track.h:255
int m_Drill
Definition: class_track.h:391
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_track.cpp:89
unsigned STATUS_FLAGS
Definition: base_struct.h:156
ENDPOINT_T
Definition: class_track.h:53
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
PCB_LAYER_ID m_BottomLayer
The bottom layer of the via (the top layer is in m_Layer)
Definition: class_track.h:387
bool ApproxCollinear(const SEG &aSeg) const
Definition: seg.h:249
unsigned int ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: base_struct.h:134
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer.
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:69
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
const wxPoint GetPosition() const override
Definition: class_track.h:309
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
void SetDrillDefault()
Function SetDrillDefault sets the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: class_track.h:372
bool ApproxCollinear(const TRACK &aTrack)
Definition: class_track.h:184
Definition: seg.h:39
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_track.h:315
void SetState(int type, int state)
Definition: base_struct.h:244
int GetWidth() const
Definition: class_track.h:103
STATUS_FLAGS IsPointOnEnds(const wxPoint &point, int min_dist=0) const
Function IsPointOnEnds returns STARTPOINT if point if near (dist = min_dist) start point,...
void SetTopLayer(PCB_LAYER_ID aLayer)
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:99
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:351
VIATYPE GetViaType() const
Definition: class_track.h:336
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
PCB_LAYER_ID TopLayer() const
const wxPoint & GetEnd() const
Definition: class_track.h:106
void SetBottomLayer(PCB_LAYER_ID aLayer)
VIATYPE
Definition: class_track.h:60
bool IsNull() const
Function IsNull returns true if segment length is zero.
Definition: class_track.h:172
void SetStart(const wxPoint &aStart)
Definition: class_track.h:108
void GetMsgPanelInfoBase_Common(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
TRACK(BOARD_ITEM *aParent, KICAD_T idtype=PCB_TRACE_T)
Definition: class_track.cpp:62
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
VIEW.
Definition: view.h:61
SEARCH_RESULT
Definition: base_struct.h:54
void SanitizeLayers()
Function SanitizeLayers Check so that the layers are correct dependin on the type of via,...
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition: class_track.h:113
void GetMsgPanelInfoBase(EDA_UNITS aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfoBase Display info about the track segment only, and does not calculate the fu...
void SetViaType(VIATYPE aViaType)
Definition: class_track.h:341
PCB_LAYER_ID BottomLayer() const
int GetState(int type) const
Definition: base_struct.h:239
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
Definition of PCB_DISPLAY_OPTIONS class.
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: class_track.cpp:83
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207
void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &aOffset=ZeroOffset) override
Function Print BOARD_ITEMs have their own color information.
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_track.h:191