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-2017 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 <pcbnew.h>
35 #include <class_board_item.h>
36 #include <board_connected_item.h>
37 #include <pcb_display_options.h>
38 
39 #include <trigo.h>
40 
41 
42 class TRACK;
43 class VIA;
44 class D_PAD;
45 class MSG_PANEL_ITEM;
46 class SHAPE_POLY_SET;
47 
48 // Via types
49 // Note that this enum must be synchronized to GAL_LAYER_ID
51 {
52  VIA_THROUGH = 3, /* Always a through hole via */
53  VIA_BLIND_BURIED = 2, /* this via can be on internal layers */
54  VIA_MICROVIA = 1, /* this via which connect from an external layer
55  * to the near neighbor internal layer */
56  VIA_NOT_DEFINED = 0 /* not yet used */
57 };
58 
59 #define UNDEFINED_DRILL_DIAMETER -1 //< Undefined via drill diameter.
60 
61 #define MIN_VIA_DRAW_SIZE 4
62 
63 
79 TRACK* GetTrack( TRACK* aStartTrace, const TRACK* aEndTrace,
80  const wxPoint& aPosition, LSET aLayerMask );
81 
83 {
84 public:
85  static inline bool ClassOf( const EDA_ITEM* aItem )
86  {
87  return aItem && PCB_TRACE_T == aItem->Type();
88  }
89 
90  BOARD_CONNECTED_ITEM* start; // pointers to a connected item (pad or track)
92 
93  double m_Param; // Auxiliary variable ( used in some computations )
94 
95  TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
96 
97  // Do not create a copy constructor. The one generated by the compiler is adequate.
98 
99  TRACK* Next() const { return static_cast<TRACK*>( Pnext ); }
100  TRACK* Back() const { return static_cast<TRACK*>( Pback ); }
101 
102  virtual void Move( const wxPoint& aMoveVector ) override
103  {
104  m_Start += aMoveVector;
105  m_End += aMoveVector;
106  }
107 
108  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
109 
110  virtual void Flip( const wxPoint& aCentre ) override;
111 
112  void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; }
113  const wxPoint GetPosition() const override { return m_Start; }
114 
115  void SetWidth( int aWidth ) { m_Width = aWidth; }
116  int GetWidth() const { return m_Width; }
117 
118  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
119  const wxPoint& GetEnd() const { return m_End; }
120 
121  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
122  const wxPoint& GetStart() const { return m_Start; }
123 
124 
126  const wxPoint& GetEndPoint( ENDPOINT_T aEndPoint ) const
127  {
128  if( aEndPoint == ENDPOINT_START )
129  return m_Start;
130  else
131  return m_End;
132  }
133 
134  // Virtual function
135  const EDA_RECT GetBoundingBox() const override;
136 
137  bool IsLocked() const override
138  {
139  return GetState( TRACK_LOCKED );
140  }
141 
142  void SetLocked( bool aLocked ) override
143  {
144  return SetState( TRACK_LOCKED, aLocked );
145  }
146 
158  TRACK* GetBestInsertPoint( BOARD* aPcb );
159 
160  /* Search (within the track linked list) the first segment matching the netcode
161  * ( the linked list is always sorted by net codes )
162  */
163  TRACK* GetStartNetCode( int NetCode );
164 
165  /* Search (within the track linked list) the last segment matching the netcode
166  * ( the linked list is always sorted by net codes )
167  */
168  TRACK* GetEndNetCode( int NetCode );
169 
175  double GetLength() const
176  {
177  return GetLineLength( m_Start, m_End );
178  }
179 
180  /* Display on screen: */
181  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
182  GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
183 
197  int aClearanceValue,
198  int aCircleToSegmentsCount,
199  double aCorrectionFactor ) const override;
207  STATUS_FLAGS IsPointOnEnds( const wxPoint& point, int min_dist = 0 );
208 
213  bool IsNull();
214 
215  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
216 
221  wxString ShowWidth() const;
222 
223  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
224 
225  virtual bool HitTest( const wxPoint& aPosition ) const override;
226 
227  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
228 
237  VIA* GetVia( const wxPoint& aPosition, PCB_LAYER_ID aLayer = UNDEFINED_LAYER );
238 
249  VIA* GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LSET aLayerMask );
250 
266  TRACK* GetTrack( TRACK* aStartTrace, TRACK* aEndTrace, ENDPOINT_T aEndPoint,
267  bool aSameNetOnly, bool aSequential );
268 
279  int GetEndSegments( int NbSegm, TRACK** StartTrack, TRACK** EndTrack );
280 
281  wxString GetClass() const override
282  {
283  return wxT( "TRACK" );
284  }
285 
295  virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const override;
296 
297  virtual wxString GetSelectMenuText() const override;
298 
299  BITMAP_DEF GetMenuImage() const override;
300 
301  virtual EDA_ITEM* Clone() const override;
302 
303  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
304 
305  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
306 
307  virtual void SwapData( BOARD_ITEM* aImage ) override;
308 
309 #if defined (DEBUG)
310  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
311 
317  static wxString ShowState( int stateBits );
318 
319 #endif
320 
321 protected:
327  virtual void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
328 
329 
332  void GetMsgPanelInfoBase_Common( std::vector< MSG_PANEL_ITEM >& aList );
333 
336  void DrawShortNetname( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
337  COLOR4D aBgColor );
338 
339  int m_Width;
342 
343 private:
344  // make SetNext() and SetBack() private so that they may not be called from anywhere.
345  // list management is done on TRACKs using DLIST<TRACK> only.
346  void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
347  void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
348 };
349 
350 
351 class SEGZONE : public TRACK
352 {
353 public:
354  SEGZONE( BOARD_ITEM* aParent );
355 
356  // Do not create a copy constructor. The one generated by the compiler is adequate.
357 
358  wxString GetClass() const override
359  {
360  return wxT( "ZONE" );
361  }
362 
363 
364  SEGZONE* Next() const { return static_cast<SEGZONE*>( Pnext ); }
365 
366  wxString GetSelectMenuText() const override;
367 
368  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
369  GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
370 
371  BITMAP_DEF GetMenuImage() const override;
372 
373  EDA_ITEM* Clone() const override;
374 
375 protected:
376  virtual void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList ) override;
377 };
378 
379 
380 class VIA : public TRACK
381 {
382 public:
383  VIA( BOARD_ITEM* aParent );
384 
385  static inline bool ClassOf( const EDA_ITEM *aItem )
386  {
387  return aItem && PCB_VIA_T == aItem->Type();
388  }
389 
390  // Do not create a copy constructor. The one generated by the compiler is adequate.
391 
392  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
393  GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
394 
395  bool IsOnLayer( PCB_LAYER_ID aLayer ) const override;
396 
397  virtual LSET GetLayerSet() const override;
398 
406  void SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer );
407 
408  void SetBottomLayer( PCB_LAYER_ID aLayer );
409  void SetTopLayer( PCB_LAYER_ID aLayer );
410 
418  void LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const;
419 
420  PCB_LAYER_ID TopLayer() const;
421  PCB_LAYER_ID BottomLayer() const;
422 
428  void SanitizeLayers();
429 
430  const wxPoint GetPosition() const override { return m_Start; }
431  void SetPosition( const wxPoint& aPoint ) override { m_Start = aPoint; m_End = aPoint; }
432 
433  virtual bool HitTest( const wxPoint& aPosition ) const override;
434 
435  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
436 
437  wxString GetClass() const override
438  {
439  return wxT( "VIA" );
440  }
441 
442  wxString GetSelectMenuText() const override;
443 
444  BITMAP_DEF GetMenuImage() const override;
445 
446  EDA_ITEM* Clone() const override;
447 
448  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
449 
450  virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
451 
452  virtual void Flip( const wxPoint& aCentre ) override;
453 
454 #if defined (DEBUG)
455  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
456 #endif
457 
458  VIATYPE_T GetViaType() const { return m_ViaType; }
459  void SetViaType( VIATYPE_T aViaType ) { m_ViaType = aViaType; }
460 
466  void SetDrill( int aDrill ) { m_Drill = aDrill; }
467 
473  int GetDrill() const { return m_Drill; }
474 
481  int GetDrillValue() const;
482 
488 
493  bool IsDrillDefault() const { return m_Drill <= 0; }
494 
495  virtual void SwapData( BOARD_ITEM* aImage ) override;
496 
497 protected:
498  virtual void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList ) override;
499 
500 private:
503 
504  VIATYPE_T m_ViaType; // Type of via
505 
506  int m_Drill; // for vias: via drill (- 1 for default value)
507 };
508 
509 
511 inline VIA* GetFirstVia( TRACK* aTrk, const TRACK* aStopPoint = NULL )
512 {
513  while( aTrk && (aTrk != aStopPoint) && (aTrk->Type() != PCB_VIA_T) )
514  aTrk = aTrk->Next();
515 
516  // It could stop because of the stop point, not on a via
517  if( aTrk && (aTrk->Type() == PCB_VIA_T) )
518  return static_cast<VIA*>( aTrk );
519  else
520  return NULL;
521 }
522 
523 
525 inline TRACK* GetFirstTrack( TRACK* aTrk, const TRACK* aStopPoint = NULL )
526 {
527  while( aTrk && ( aTrk != aStopPoint ) && ( aTrk->Type() != PCB_TRACE_T ) )
528  aTrk = aTrk->Next();
529 
530  // It could stop because of the stop point, not on a via
531  if( aTrk && ( aTrk->Type() == PCB_TRACE_T ) )
532  return static_cast<TRACK*>( aTrk );
533  else
534  return NULL;
535 }
536 
537 #endif // CLASS_TRACK_H
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:137
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
TRACK * GetTrack(TRACK *aStartTrace, TRACK *aEndTrace, ENDPOINT_T aEndPoint, bool aSameNetOnly, bool aSequential)
Function GetTrack returns the trace segment connected to the segment at aEndPoint from aStartTrace to...
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:176
bool IsNull()
Function IsNull returns true if segment length is zero.
wxPoint m_Start
Line start point.
Definition: class_track.h:340
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:191
VIATYPE_T m_ViaType
Definition: class_track.h:504
PNG memory record (file in memory).
Definition: bitmap_types.h:41
static bool ClassOf(const EDA_ITEM *aItem)
Definition: class_track.h:85
void SetViaType(VIATYPE_T aViaType)
Definition: class_track.h:459
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:431
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Function IsOnLayer tests to see if this object is on the given layer.
Class 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:118
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
virtual void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
STATUS_FLAGS IsPointOnEnds(const wxPoint &point, int min_dist=0)
Function IsPointOnEnds returns STARTPOINT if point if near (dist = min_dist) start point...
TRACK * GetTrack(TRACK *aStartTrace, const TRACK *aEndTrace, const wxPoint &aPosition, LSET aLayerMask)
Function GetTrack is a helper function to locate a trace segment having an end point at aPosition on ...
Definition: class_track.cpp:68
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_track.h:358
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
int GetEndSegments(int NbSegm, TRACK **StartTrack, TRACK **EndTrack)
Function GetEndSegments get the segments connected to the end point of the track. ...
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
VIATYPE_T
Definition: class_track.h:50
virtual void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
int GetState(int type) const
Definition: base_struct.h:248
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
TRACK * Back() const
Definition: class_track.h:100
int GetDrill() const
Function GetDrill returns the local drill setting for this VIA.
Definition: class_track.h:473
const wxPoint & GetEnd() const
Definition: class_track.h:119
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:95
double m_Param
Definition: class_track.h:93
int m_Width
Thickness of track, or via diameter.
Definition: class_track.h:339
void SetWidth(int aWidth)
Definition: class_track.h:115
ENDPOINT_T
Flag used in locate routines (from which endpoint work)
Definition: pcbnew.h:58
SEGZONE * Next() const
Definition: class_track.h:364
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:100
VIA * GetVia(const wxPoint &aPosition, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Function GetVia finds the first VIA object at aPosition on aLayer starting at the trace...
void SetLocked(bool aLocked) override
Function SetLocked modifies &#39;lock&#39; status for of the item.
Definition: class_track.h:142
static bool ClassOf(const EDA_ITEM *aItem)
Definition: class_track.h:385
PCB_LAYER_ID
A quick note on layer IDs:
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Class LSET is a set of PCB_LAYER_IDs.
VIATYPE_T GetViaType() const
Definition: class_track.h:458
const wxPoint GetPosition() const override
Definition: class_track.h:113
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
Class SHAPE_POLY_SET.
const wxPoint & GetStart() const
Definition: class_track.h:122
wxPoint m_End
Line end point.
Definition: class_track.h:341
int m_Drill
Definition: class_track.h:506
void DrawShortNetname(EDA_DRAW_PANEL *panel, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aBgColor)
Helper for drawing the short netname in tracks.
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition: class_track.h:126
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const override
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
unsigned STATUS_FLAGS
Definition: base_struct.h:142
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:502
TRACK * GetEndNetCode(int NetCode)
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: base_struct.h:124
virtual void Move(const wxPoint &aMoveVector) override
Function Move move this object.
Definition: class_track.h:102
#define UNDEFINED_DRILL_DIAMETER
Definition: class_track.h:59
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:430
virtual wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
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:487
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
wxString ShowWidth() const
Function ShowWidth returns the width of the track in displayable user units.
TRACK * GetBestInsertPoint(BOARD *aPcb)
Function GetBestInsertPoint searches the "best" insertion point within the track linked list...
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_track.h:437
TRACK * Next() const
Definition: class_track.h:99
void SetState(int type, int state)
Definition: base_struct.h:253
TRACK * GetStartNetCode(int NetCode)
void SetBack(EDA_ITEM *aBack)
Definition: class_track.h:347
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void GetMsgPanelInfoBase_Common(std::vector< MSG_PANEL_ITEM > &aList)
Helper function for the common panel info.
int GetWidth() const
Definition: class_track.h:116
void SetPosition(const wxPoint &aPos) override
Definition: class_track.h:112
Class 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:466
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
virtual void GetMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfoBase Display info about the track segment only, and does not calculate the fu...
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:175
void SetStart(const wxPoint &aStart)
Definition: class_track.h:121
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
TRACK(BOARD_ITEM *aParent, KICAD_T idtype=PCB_TRACE_T)
Definition: class_track.cpp:96
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
Class VIEW.
Definition: view.h:58
void SetNext(EDA_ITEM *aNext)
Definition: class_track.h:346
SEARCH_RESULT
Definition: base_struct.h:64
Class BOARD_CONNECTED_ITEM.
BOARD_CONNECTED_ITEM * end
Definition: class_track.h:91
Definition of PCB_DISPLAY_OPTIONS class.
BOARD_CONNECTED_ITEM * start
Definition: class_track.h:90
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:175
bool IsDrillDefault() const
Function IsDrillDefault.
Definition: class_track.h:493
TRACK * GetFirstTrack(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first TRACK object. Returns NULL if not found (or NULL passed) ...
Definition: class_track.h:525
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_track.h:281
VIA * GetFirstVia(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first VIA o NULL if not found (or NULL passed)
Definition: class_track.h:511