KiCad PCB EDA Suite
editrack.cpp File Reference
#include <fctsys.h>
#include <class_drawpanel.h>
#include <trigo.h>
#include <wxPcbStruct.h>
#include <colors_selection.h>
#include <pcbnew.h>
#include <drc_stuff.h>
#include <protos.h>
#include <class_board.h>
#include <class_track.h>
#include <class_zone.h>
#include <connectivity.h>

Go to the source code of this file.

Functions

static void Abort_Create_Track (EDA_DRAW_PANEL *panel, wxDC *DC)
 
void ShowNewTrackWhenMovingCursor (EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
 
static void ComputeBreakPoint (TRACK *track, int SegmentCount, wxPoint end)
 Compute new track angle based on previous track. More...
 
static void DeleteNullTrackSegments (BOARD *pcb, DLIST< TRACK > &aTrackList)
 
static void EnsureEndTrackOnPad (D_PAD *Pad)
 
TRACKLocateIntrusion (TRACK *listStart, TRACK *aTrack, LAYER_NUM aLayer, const wxPoint &aRef)
 
static void PushTrack (EDA_DRAW_PANEL *panel)
 Function PushTrack detects if the mouse is pointing into a conflicting track. More...
 
void DrawViaCirclesWhenEditingNewTrack (EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
 
wxPoint CalculateSegmentEndPoint (const wxPoint &aPosition, const wxPoint &aOrigin)
 Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the origin aOrigin and aPosition. More...
 

Variables

static PICKED_ITEMS_LIST s_ItemsListPicker
 

Function Documentation

static void Abort_Create_Track ( EDA_DRAW_PANEL panel,
wxDC *  DC 
)
static

Definition at line 61 of file editrack.cpp.

References PICKED_ITEMS_LIST::ClearListAndDeleteItems(), EDA_DRAW_FRAME::ClearMsgPanel(), DHEAD::DeleteAll(), BOARD::DrawHighLight(), dyn_cast(), g_CurrentTrackList, PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCurItem(), BOARD::GetHighLightNetCode(), EDA_DRAW_PANEL::GetParent(), PCB_EDIT_FRAME::HighLight(), BOARD::IsHighLightNetON(), BOARD::PopHighLight(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_FRAME::SetCurItem(), and ShowNewTrackWhenMovingCursor().

Referenced by PCB_EDIT_FRAME::Begin_Route().

62 {
63  PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Panel->GetParent();
64  BOARD* pcb = frame->GetBoard();
65  TRACK* track = dyn_cast<TRACK*>( frame->GetCurItem() );
66 
67  if( track )
68  {
69  // Erase the current drawing
70  ShowNewTrackWhenMovingCursor( Panel, DC, wxDefaultPosition, false );
71 
72  if( pcb->IsHighLightNetON() )
73  frame->HighLight( DC );
74 
75  pcb->PopHighLight();
76 
77  if( pcb->IsHighLightNetON() )
78  pcb->DrawHighLight( Panel, DC, pcb->GetHighLightNetCode() );
79 
80  frame->ClearMsgPanel();
81 
82  // Undo pending changes (mainly a lock point creation) and clear the
83  // undo picker list:
84  frame->PutDataInPreviousState( &s_ItemsListPicker, false, false );
86 
87  // Delete current (new) track
89  }
90 
91  frame->SetCurItem( NULL );
92 }
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
BOARD * GetBoard() const
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:73
void PopHighLight()
Function PopHighLight retrieve a previously saved high light info.
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList, bool aRedoCommand, bool aRebuildRatsnet=true)
Function PutDataInPreviousState Used in undo or redo command.
Definition: undo_redo.cpp:377
void HighLight(wxDC *DC)
Function HighLight.
Definition: highlight.cpp:101
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void ShowNewTrackWhenMovingCursor(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Definition: editrack.cpp:672
static PICKED_ITEMS_LIST s_ItemsListPicker
Definition: editrack.cpp:56
bool IsHighLightNetON() const
Function IsHighLightNetON.
Definition: class_board.h:373
int GetHighLightNetCode() const
Function GetHighLightNetCode.
Definition: class_board.h:358
void DrawHighLight(EDA_DRAW_PANEL *aDrawPanel, wxDC *aDC, int aNetCode)
Function DrawHighLight redraws the objects in the board that are associated with the given aNetCode a...
Definition: tracepcb.cpp:247
BOARD_ITEM * GetCurItem()
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:764
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
wxPoint CalculateSegmentEndPoint ( const wxPoint aPosition,
const wxPoint aOrigin 
)

Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the origin aOrigin and aPosition.

Definition at line 832 of file editrack.cpp.

References abs, PNS::angle(), min, wxPoint::x, and wxPoint::y.

Referenced by DrawSegment(), Show_New_Edge_While_Move_Mouse(), and ShowNewTrackWhenMovingCursor().

833 {
834  // Determine end point for a segment direction 0, 90, or 45 degrees
835  // depending on it's position from the origin \a aOrigin and \a aPosition.
836  wxPoint endPoint;
837 
838  int deltax = aPosition.x - aOrigin.x;
839  int deltay = aPosition.y - aOrigin.y;
840 
841  deltax = abs( deltax );
842  deltay = abs( deltay );
843  int angle = 45;
844 
845  if( deltax >= deltay )
846  {
847  if( deltax == 0 )
848  angle = 0;
849  else if( ( (deltay << 6 ) / deltax ) < 26 )
850  angle = 0;
851  }
852  else
853  {
854  angle = 45;
855 
856  if( deltay == 0 )
857  angle = 90;
858  else if( ( (deltax << 6 ) / deltay ) < 26 )
859  angle = 90;
860  }
861 
862  switch( angle )
863  {
864  case 0:
865  endPoint.x = aPosition.x;
866  endPoint.y = aOrigin.y;
867  break;
868 
869  case 45:
870  deltax = std::min( deltax, deltay );
871  deltay = deltax;
872 
873  // Recalculate the signs for deltax and deltaY.
874  if( ( aPosition.x - aOrigin.x ) < 0 )
875  deltax = -deltax;
876 
877  if( ( aPosition.y - aOrigin.y ) < 0 )
878  deltay = -deltay;
879 
880  endPoint.x = aOrigin.x + deltax;
881  endPoint.y = aOrigin.y + deltay;
882  break;
883 
884  case 90:
885  endPoint.x = aOrigin.x;
886  endPoint.y = aPosition.y;
887  break;
888  }
889 
890  return endPoint;
891 }
#define abs(a)
Definition: auxiliary.h:84
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
#define min(a, b)
Definition: auxiliary.h:85
void ComputeBreakPoint ( TRACK track,
int  n,
wxPoint  end 
)
static

Compute new track angle based on previous track.

Definition at line 897 of file editrack.cpp.

References abs, TRACK::Back(), g_Alternate_Track_Posture, TRACK::GetEnd(), TRACK::GetStart(), TRACK::IsNull(), min, TRACK::SetEnd(), TRACK::SetStart(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

898 {
899  int iDx = 0;
900  int iDy = 0;
901  int iAngle = 0;
902 
903  if( SegmentCount <= 0 )
904  return;
905 
906  if( track == NULL )
907  return;
908 
909  TRACK* newTrack = track;
910  track = track->Back();
911  SegmentCount--;
912 
913  if( track )
914  {
915  iDx = end.x - track->GetStart().x;
916  iDy = end.y - track->GetStart().y;
917 
918  iDx = abs( iDx );
919  iDy = abs( iDy );
920  }
921 
922  TRACK* lastTrack = track ? track->Back() : NULL;
923 
924  if( lastTrack )
925  {
926  if(( (lastTrack->GetEnd().x == lastTrack->GetStart().x)
927  || (lastTrack->GetEnd().y == lastTrack->GetStart().y) )
929  {
930  iAngle = 45;
931  }
932  }
933  else
934  {
936  {
937  iAngle = 45;
938  }
939  }
940 
941  if( iAngle == 0 )
942  {
943  if( iDx >= iDy )
944  iAngle = 0;
945  else
946  iAngle = 90;
947  }
948 
949  if( track == NULL )
950  iAngle = -1;
951 
952  switch( iAngle )
953  {
954  case -1:
955  break;
956 
957  case 0:
958  if( ( end.x - track->GetStart().x ) < 0 )
959  track->SetEnd(wxPoint( end.x + iDy, track->GetStart().y));
960  else
961  track->SetEnd(wxPoint( end.x - iDy, track->GetStart().y));
962  break;
963 
964  case 45:
965  iDx = std::min( iDx, iDy );
966  iDy = iDx;
967 
968  // Recalculate the signs for deltax and deltaY.
969  if( ( end.x - track->GetStart().x ) < 0 )
970  iDx = -iDx;
971 
972  if( ( end.y - track->GetStart().y ) < 0 )
973  iDy = -iDy;
974 
975  track->SetEnd(wxPoint(track->GetStart().x + iDx, track->GetStart().y + iDy));
976  break;
977 
978  case 90:
979  if( ( end.y - track->GetStart().y ) < 0 )
980  track->SetEnd(wxPoint(track->GetStart().x , end.y + iDx));
981  else
982  track->SetEnd(wxPoint(track->GetStart().x , end.y - iDx));
983  break;
984  }
985 
986  if( track )
987  {
988  if( track->IsNull() )
989  track->SetEnd( end );
990 
991  newTrack->SetStart( track->GetEnd() );
992  }
993 
994  newTrack->SetEnd( end );
995 }
bool IsNull()
Function IsNull returns true if segment length is zero.
bool g_Alternate_Track_Posture
Definition: pcbnew.cpp:73
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
#define abs(a)
Definition: auxiliary.h:84
TRACK * Back() const
Definition: class_track.h:99
const wxPoint & GetEnd() const
Definition: class_track.h:118
const wxPoint & GetStart() const
Definition: class_track.h:121
void SetStart(const wxPoint &aStart)
Definition: class_track.h:120
#define min(a, b)
Definition: auxiliary.h:85
void DeleteNullTrackSegments ( BOARD pcb,
DLIST< TRACK > &  aTrackList 
)
static

Definition at line 1001 of file editrack.cpp.

References BEGIN_ONPAD, TRACK::end, END_ONPAD, ENDPOINT_END, DHEAD::GetCount(), DLIST< T >::GetFirst(), BOARD::GetPad(), TRACK::IsNull(), TRACK::Next(), PCB_PAD_T, DLIST< T >::Remove(), EDA_ITEM::SetState(), EDA_ITEM::SetStatus(), TRACK::start, and EDA_ITEM::Type().

Referenced by PCB_EDIT_FRAME::End_Route().

1002 {
1003  if( aTrackList.GetCount() == 0 )
1004  return;
1005 
1006  TRACK* track = aTrackList.GetFirst();
1007  TRACK* firsttrack = track;
1008  TRACK* oldtrack;
1009 
1010  BOARD_CONNECTED_ITEM* lockPoint = track->start;
1011 
1012  while( track != NULL )
1013  {
1014  oldtrack = track;
1015  track = track->Next();
1016 
1017  if( !oldtrack->IsNull() )
1018  {
1019  continue;
1020  }
1021 
1022  // NULL segment, delete it
1023  if( firsttrack == oldtrack )
1024  firsttrack = track;
1025 
1026  delete aTrackList.Remove( oldtrack );
1027  }
1028 
1029  if( aTrackList.GetCount() == 0 )
1030  return; // all the new track segments have been deleted
1031 
1032  // we must set the pointers on connected items and the connection status
1033  oldtrack = track = firsttrack;
1034  firsttrack->start = NULL;
1035 
1036  while( track != NULL )
1037  {
1038  oldtrack = track;
1039  track = track->Next();
1040  oldtrack->end = track;
1041 
1042  if( track )
1043  track->start = oldtrack;
1044 
1045  oldtrack->SetStatus( 0 );
1046  }
1047 
1048  firsttrack->start = lockPoint;
1049 
1050  if( lockPoint && lockPoint->Type()==PCB_PAD_T )
1051  firsttrack->SetState( BEGIN_ONPAD, true );
1052 
1053  track = firsttrack;
1054 
1055  while( track != NULL )
1056  {
1057  TRACK* next_track = track->Next();
1058  lockPoint = pcb->GetPad( track, ENDPOINT_END );
1059 
1060  if( lockPoint )
1061  {
1062  track->end = lockPoint;
1063  track->SetState( END_ONPAD, true );
1064 
1065  if( next_track )
1066  {
1067  next_track->start = lockPoint;
1068  next_track->SetState( BEGIN_ONPAD, true );
1069  }
1070  }
1071 
1072  track = next_track;
1073  }
1074 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
bool IsNull()
Function IsNull returns true if segment length is zero.
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:133
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
D_PAD * GetPad(unsigned aIndex) const
Function GetPad.
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:132
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:163
TRACK * Next() const
Definition: class_track.h:98
void SetState(int type, int state)
Definition: base_struct.h:242
void SetStatus(STATUS_FLAGS aStatus)
Definition: base_struct.h:251
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
BOARD_CONNECTED_ITEM * end
Definition: class_track.h:90
BOARD_CONNECTED_ITEM * start
Definition: class_track.h:89
void DrawViaCirclesWhenEditingNewTrack ( EDA_RECT aPanelClipBox,
wxDC *  aDC,
const wxPoint aPos,
int  aViaRadius,
int  aViaRadiusWithClearence,
COLOR4D  aColor 
)
inline

Definition at line 658 of file editrack.cpp.

References GRCircle(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

663 {
664  //Current viasize clearance circle
665  GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadiusWithClearence, aColor );
666  //Current viasize circle
667  GRCircle( aPanelClipBox, aDC, aPos.x, aPos.y, aViaRadius, aColor );
668 }
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:791
void EnsureEndTrackOnPad ( D_PAD Pad)
static

Definition at line 1081 of file editrack.cpp.

References TRACK::Clone(), TRACK::end, END_ONPAD, g_CurrentTrackList, g_CurrentTrackSegment, D_PAD::GetPosition(), and DLIST< T >::PushBack().

Referenced by PCB_EDIT_FRAME::End_Route().

1082 {
1083  if( g_CurrentTrackSegment->GetEnd() == aPad->GetPosition() ) // Ok !
1084  {
1085  g_CurrentTrackSegment->end = aPad;
1086  g_CurrentTrackSegment->SetState( END_ONPAD, true );
1087  return;
1088  }
1089 
1090  TRACK* lasttrack = g_CurrentTrackSegment;
1091 
1092  if( !g_CurrentTrackSegment->IsNull() )
1093  {
1094  // Must create a new segment, from track end to pad center
1095  g_CurrentTrackList.PushBack( (TRACK*)lasttrack->Clone() );
1096 
1097  lasttrack->end = g_CurrentTrackSegment;
1098  }
1099 
1100  g_CurrentTrackSegment->SetEnd( aPad->GetPosition() );
1101  g_CurrentTrackSegment->SetState( END_ONPAD, false );
1102 
1103  g_CurrentTrackSegment->end = aPad;
1104  g_CurrentTrackSegment->SetState( END_ONPAD, true );
1105 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:100
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:133
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
BOARD_CONNECTED_ITEM * end
Definition: class_track.h:90
TRACK* LocateIntrusion ( TRACK listStart,
TRACK aTrack,
LAYER_NUM  aLayer,
const wxPoint aRef 
)

Definition at line 540 of file editrack.cpp.

References BUSY, dist, TRACK::GetClearance(), BOARD_CONNECTED_ITEM::GetNetCode(), TRACK::GetWidth(), IS_DELETED, TRACK::Next(), PCB_TRACE_T, TestSegmentHit(), wxPoint::x, and wxPoint::y.

Referenced by PCB_EDIT_FRAME::GeneralControl(), and PushTrack().

541 {
542  int net = aTrack->GetNetCode();
543  int width = aTrack->GetWidth();
544 
545  TRACK* found = NULL;
546 
547  for( TRACK* track = listStart; track; track = track->Next() )
548  {
549  if( track->Type() == PCB_TRACE_T ) // skip vias
550  {
551  if( track->GetState( BUSY | IS_DELETED ) )
552  continue;
553 
554  if( aLayer != track->GetLayer() )
555  continue;
556 
557  if( track->GetNetCode() == net )
558  continue;
559 
560  // TRACK::HitTest
561  int dist = (width + track->GetWidth()) / 2 + aTrack->GetClearance( track );
562 
563  if( !TestSegmentHit( aRef, track->GetStart(), track->GetEnd(), dist ) )
564  continue;
565 
566  found = track;
567 
568  // prefer intrusions from the side, not the end
569  wxPoint pos = aRef - track->GetStart();
570  wxPoint vec = track->GetEnd() - track->GetStart();
571  double tmp = (double) pos.x * vec.x + (double) pos.y * vec.y;
572 
573  if( tmp >= 0 && tmp <= (double) vec.x * vec.x + (double) vec.y * vec.y )
574  break;
575  }
576  }
577 
578  return found;
579 }
static const int dist[10][10]
Definition: dist.cpp:57
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:134
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
#define IS_DELETED
Definition: base_struct.h:116
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
int GetNetCode() const
Function GetNetCode.
TRACK * Next() const
Definition: class_track.h:98
int GetWidth() const
Definition: class_track.h:115
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:142
static void PushTrack ( EDA_DRAW_PANEL panel)
static

Function PushTrack detects if the mouse is pointing into a conflicting track.

In this case, it tries to push the new track out of the conflicting track's clearance zone. This gives us a cheap mechanism for drawing tracks that tightly follow others, independent of grid settings.

KNOWN BUGS:

  • we do the same sort of search and calculation up to three times: 1) we search for magnetic hits (in controle.cpp) 2) we check if there's a DRC violation in the making (also controle.cpp) 3) we try to fix the DRC violation (here)
  • if we have a magnetic hit and a DRC violation at the same time, we choose the magnetic hit instead of solving the violation
  • should locate conflicting tracks also when we're crossing over them

Definition at line 598 of file editrack.cpp.

References dist, FindBestGridPointOnTrack(), g_CurrentTrackSegment, BOARD_ITEM::GetBoard(), TRACK::GetClearance(), EDA_DRAW_FRAME::GetCrossHairPosition(), TRACK::GetEnd(), BOARD_CONNECTED_ITEM::GetNetCode(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_FRAME::GetScreen(), TRACK::GetStart(), TRACK::GetWidth(), KiROUND(), LocateIntrusion(), PCB_SCREEN::m_Active_Layer, BOARD::m_Track, EDA_DRAW_FRAME::RefPos(), TRACK::SetEnd(), wxPoint::x, and wxPoint::y.

Referenced by ShowNewTrackWhenMovingCursor().

599 {
600  PCB_SCREEN* screen = (PCB_SCREEN*) panel->GetParent()->GetScreen();
601  BOARD* pcb = ( (PCB_BASE_FRAME*) (panel->GetParent()) )->GetBoard();
602  wxPoint cursor = panel->GetParent()->GetCrossHairPosition();
603  wxPoint cv, vec, n;
604  TRACK* track = g_CurrentTrackSegment;
605  TRACK* other;
606  double det;
607  int dist;
608  double f;
609 
610  other = LocateIntrusion( pcb->m_Track, track, screen->m_Active_Layer, panel->GetParent()->RefPos( true ) );
611 
612  // are we currently pointing into a conflicting trace ?
613  if( !other )
614  return;
615 
616  if( other->GetNetCode() == track->GetNetCode() )
617  return;
618 
619  cv = cursor - other->GetStart();
620  vec = other->GetEnd() - other->GetStart();
621 
622  det = (double) cv.x * vec.y - (double) cv.y * vec.x;
623 
624  // cursor is right at the center of the old track
625  if( !det )
626  return;
627 
628  dist = (track->GetWidth() + 1) / 2 + (other->GetWidth() + 1) / 2 + track->GetClearance( other ) + 2;
629 
630  /*
631  * DRC wants >, so +1.
632  * We may have a quantization error of 1/sqrt(2), so +1 again.
633  */
634 
635  // Vector "n" is perpendicular to "other", pointing towards the cursor.
636  if( det > 0 )
637  {
638  n.x = vec.y;
639  n.y = -vec.x;
640  }
641  else
642  {
643  n.x = -vec.y;
644  n.y = vec.x;
645  }
646 
647  f = dist / hypot( double(n.x), double(n.y) );
648  n.x = KiROUND( f * n.x );
649  n.y = KiROUND( f * n.y );
650 
651  wxPoint hp = track->GetEnd();
652  FindBestGridPointOnTrack( &hp, cursor, other );
653  track->SetEnd( hp + n );
654 }
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:100
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:117
static const int dist[10][10]
Definition: dist.cpp:57
PCB_LAYER_ID m_Active_Layer
const wxPoint & GetEnd() const
Definition: class_track.h:118
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:309
const wxPoint & GetStart() const
Definition: class_track.h:121
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
TRACK * LocateIntrusion(TRACK *listStart, TRACK *aTrack, LAYER_NUM aLayer, const wxPoint &aRef)
Definition: editrack.cpp:540
virtual int GetClearance(BOARD_CONNECTED_ITEM *aItem=NULL) const override
Function GetClearance returns the clearance in internal units.
bool FindBestGridPointOnTrack(wxPoint *aNearPos, wxPoint on_grid, const TRACK *track)
Finds the projection of a grid point on a track.
int GetNetCode() const
Function GetNetCode.
wxPoint RefPos(bool useMouse) const
Function RefPos Return the reference position, coming from either the mouse position or the cursor po...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
int GetWidth() const
Definition: class_track.h:115
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
DLIST< TRACK > m_Track
Definition: class_board.h:246
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void ShowNewTrackWhenMovingCursor ( EDA_DRAW_PANEL aPanel,
wxDC *  aDC,
const wxPoint aPosition,
bool  aErase 
)

Definition at line 672 of file editrack.cpp.

References EDA_DRAW_FRAME::AppendMsgPanel(), BEGIN_ONPAD, PCB_BASE_FRAME::BuildAirWiresTargetsList(), CalculateSegmentEndPoint(), color, ComputeBreakPoint(), DARKCYAN, DBG, DO_NOT_SHOW_CLEARANCE, DrawTraces(), DrawViaCirclesWhenEditingNewTrack(), g_ColorsSettings, g_CurrentTrackList, g_CurrentTrackSegment, g_Drc_On, g_FirstTrackSegment, g_Track_45_Only_Allowed, g_TwoSegmentTrackBuild, EDA_DRAW_PANEL::GetClipBox(), DHEAD::GetCount(), EDA_DRAW_FRAME::GetCrossHairPosition(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetCurrentViaSize(), PCB_BASE_FRAME::GetDesignSettings(), EDA_DRAW_PANEL::GetDisplayOptions(), COLORS_DESIGN_SETTINGS::GetLayerColor(), TRACK::GetLength(), D_PAD::GetPadToDieLength(), EDA_DRAW_PANEL::GetParent(), EDA_DRAW_PANEL::GetScreen(), GR_XOR, EDA_DRAW_FRAME::LengthDoubleToString(), PCB_SCREEN::m_Active_Layer, DISPLAY_OPTIONS::m_DisplayPcbTrackFill, DISPLAY_OPTIONS::m_ShowTrackClearanceMode, BOARD_DESIGN_SETTINGS::m_UseConnectedTrackWidth, PCB_TRACE_T, PushTrack(), BOARD_ITEM::SetLayer(), EDA_DRAW_FRAME::SetMsgPanel(), TRACK::SetWidth(), SHOW_CLEARANCE_ALWAYS, SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS, PCB_BASE_FRAME::TraceAirWiresToTargets(), and EDA_ITEM::Type().

Referenced by Abort_Create_Track(), PCB_EDIT_FRAME::Begin_Route(), PCB_EDIT_FRAME::Delete_Segment(), and PCB_EDIT_FRAME::End_Route().

674 {
675 // DBG( g_CurrentTrackList.VerifyListIntegrity(); );
676 
677  PCB_SCREEN* screen = (PCB_SCREEN*) aPanel->GetScreen();
678  PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent();
679  DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*) aPanel->GetDisplayOptions();
680 
681  bool tmp = displ_opts->m_DisplayPcbTrackFill;
682  displ_opts->m_DisplayPcbTrackFill = true;
683  TRACE_CLEARANCE_DISPLAY_MODE_T showTrackClearanceMode = displ_opts->m_ShowTrackClearanceMode;
684 
685  if ( g_FirstTrackSegment == NULL )
686  return;
687 
688  NETCLASSPTR netclass = g_FirstTrackSegment->GetNetClass();
689 
690  if( showTrackClearanceMode != DO_NOT_SHOW_CLEARANCE )
692 
693  // Values to Via circle
694  int boardViaRadius = frame->GetDesignSettings().GetCurrentViaSize()/2;
695  int viaRadiusWithClearence = boardViaRadius+netclass->GetClearance();
696  EDA_RECT* panelClipBox=aPanel->GetClipBox();
697 
698 #ifndef USE_WX_OVERLAY
699  // Erase old track
700  if( aErase )
701  {
703 
704  frame->TraceAirWiresToTargets( aDC );
705 
706  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
707  {
709  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
710  boardViaRadius, viaRadiusWithClearence, color);
711  }
712  }
713 #endif
714  // MacOSX seems to need this.
715  if( g_CurrentTrackList.GetCount() == 0 )
716  return;
717 
718  // Set track parameters, that can be modified while creating the track
719  g_CurrentTrackSegment->SetLayer( screen->m_Active_Layer );
720 
723 
725  {
726  TRACK* previous_track = g_CurrentTrackSegment->Back();
727 
728  if( previous_track && previous_track->Type()==PCB_TRACE_T )
729  {
730  previous_track->SetLayer( screen->m_Active_Layer );
731 
733  previous_track->SetWidth( frame->GetDesignSettings().GetCurrentTrackWidth() );
734  }
735  }
736 
738  {
740  {
741  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
742 
743  if( g_Drc_On )
744  PushTrack( aPanel );
745 
748  g_CurrentTrackSegment->GetEnd() );
749  }
750  else
751  {
752  /* Calculate of the end of the path for the permitted directions:
753  * horizontal, vertical or 45 degrees.
754  */
755  wxPoint hp = g_CurrentTrackSegment->GetEnd();
757  g_CurrentTrackSegment->GetStart() );
758  g_CurrentTrackSegment->SetEnd(hp);
759  }
760  }
761  else // Here the angle is arbitrary
762  {
763  g_CurrentTrackSegment->SetEnd( frame->GetCrossHairPosition() );
764  }
765 
766  // Redraw the new track
767  DBG( g_CurrentTrackList.VerifyListIntegrity(); );
769 
770  if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS )
771  {
773 
774  //Via diameter must have taken what we are using, rather than netclass value.
775  DrawViaCirclesWhenEditingNewTrack( panelClipBox, aDC, g_CurrentTrackSegment->GetEnd(),
776  boardViaRadius, viaRadiusWithClearence, color);
777 
778  }
779 
780  /* Display info about current segment and the full new track:
781  * Choose the interesting segment: because we are using a 2 segments step,
782  * the last segment can be null, and the previous segment can be the
783  * interesting segment.
784  */
785  TRACK* isegm = g_CurrentTrackSegment;
786 
787  if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() )
788  isegm = g_CurrentTrackSegment->Back();
789 
790  // display interesting segment info only:
791  frame->SetMsgPanel( isegm );
792 
793  // Display current track length (on board) and the the actual track len
794  // if there is an extra len due to the len die on the starting pad (if any)
795  double trackLen = 0.0;
796  double lenPadToDie = 0.0;
797  wxString msg;
798 
799  // If the starting point is on a pad, add current track length+ length die
800  if( g_FirstTrackSegment->GetState( BEGIN_ONPAD ) )
801  {
802  D_PAD* pad = (D_PAD*) g_FirstTrackSegment->start;
803  lenPadToDie = (double) pad->GetPadToDieLength();
804  }
805 
806  // calculate track len on board:
807  for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() )
808  trackLen += track->GetLength();
809 
810  msg = frame->LengthDoubleToString( trackLen );
811  frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN );
812 
813  if( lenPadToDie != 0 ) // display the track len on board and the actual track len
814  {
815  frame->AppendMsgPanel( _( "Full Len" ), msg, DARKCYAN );
816  msg = frame->LengthDoubleToString( trackLen+lenPadToDie );
817  frame->AppendMsgPanel( _( "Pad to die" ), msg, DARKCYAN );
818  }
819 
820  // Add current segments count (number of segments in this new track):
821  msg.Printf( wxT( "%d" ), g_CurrentTrackList.GetCount() );
822  frame->AppendMsgPanel( _( "Segs Count" ), msg, DARKCYAN );
823 
824  displ_opts->m_ShowTrackClearanceMode = showTrackClearanceMode;
825  displ_opts->m_DisplayPcbTrackFill = tmp;
826 
827  frame->BuildAirWiresTargetsList( NULL, g_CurrentTrackSegment->GetEnd(), g_CurrentTrackSegment->GetNetCode() );
828  frame->TraceAirWiresToTargets( aDC );
829 }
#define g_FirstTrackSegment
first segment created
Definition: pcbnew.h:101
#define g_CurrentTrackSegment
most recently created segment
Definition: pcbnew.h:100
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
void TraceAirWiresToTargets(wxDC *aDC)
Function TraceAirWiresToTargets This functions shows airwires to nearest connecting points (pads) fro...
Definition: ratsnest.cpp:194
bool g_Drc_On
Definition: pcbnew.cpp:70
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
DLIST< TRACK > g_CurrentTrackList
Definition: pcbnew.cpp:98
int GetPadToDieLength() const
Definition: class_pad.h:241
void BuildAirWiresTargetsList(BOARD_CONNECTED_ITEM *aItemRef, const wxPoint &aPosition, int aNet)
Function BuildAirWiresTargetsList Build a list of candidates that can be a coonection point when a tr...
Definition: ratsnest.cpp:171
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:132
PCB_LAYER_ID m_Active_Layer
int GetCurrentViaSize() const
Function GetCurrentViaSize.
bool m_UseConnectedTrackWidth
if true, when creating a new track starting on an existing track, use this track width ...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:107
wxPoint CalculateSegmentEndPoint(const wxPoint &aPosition, const wxPoint &aOrigin)
Determine end point for a segment direction 0, 90, or 45 degrees depending on it's position from the ...
Definition: editrack.cpp:832
void SetWidth(int aWidth)
Definition: class_track.h:114
bool m_DisplayPcbTrackFill
Definition: pcbstruct.h:71
static void PushTrack(EDA_DRAW_PANEL *panel)
Function PushTrack detects if the mouse is pointing into a conflicting track.
Definition: editrack.cpp:598
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:773
wxString LengthDoubleToString(double aValue, bool aConvertToMils=false) const
Function LengthDoubleToString is a helper to convert the double value aValue to a string in inches or...
Definition: draw_frame.cpp:817
EDA_RECT * GetClipBox()
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this frame...
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: pcbnew.cpp:68
Class DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
Definition: pcbstruct.h:62
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
Definition: pcbstruct.h:74
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:753
void DrawViaCirclesWhenEditingNewTrack(EDA_RECT *aPanelClipBox, wxDC *aDC, const wxPoint &aPos, int aViaRadius, int aViaRadiusWithClearence, COLOR4D aColor)
Definition: editrack.cpp:658
bool g_Track_45_Only_Allowed
Definition: pcbnew.cpp:74
Class EDA_RECT handles the component boundary box.
static void ComputeBreakPoint(TRACK *track, int n, wxPoint end)
Compute new track angle based on previous track.
Definition: editrack.cpp:897
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: class_track.h:171
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
#define DBG(x)
Definition: fctsys.h:33
void * GetDisplayOptions()
Function GetDisplayOptions A way to pass info to draw functions.
Definition: draw_panel.cpp:182
void DrawTraces(EDA_DRAW_PANEL *panel, wxDC *DC, TRACK *aStartTrace, int nbsegment, GR_DRAWMODE mode_color)
Function DrawTraces Draws n consecutive track segments in list.
Definition: tr_modif.cpp:49
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
bool g_TwoSegmentTrackBuild
Definition: pcbnew.cpp:76
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
TRACE_CLEARANCE_DISPLAY_MODE_T
Enum TRACE_CLEARANCE_DISPLAY_MODE_T is the set of values for DISPLAY_OPTIONS.ShowTrackClearanceMode p...
Definition: pcbstruct.h:39
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39

Variable Documentation

PICKED_ITEMS_LIST s_ItemsListPicker
static

Definition at line 56 of file editrack.cpp.